httpy package
Subpackages
- httpy.http2 package
- Subpackages
- Submodules
- httpy.http2.connection module
AsyncConnection
AsyncConnection.close()
AsyncConnection.close_on_error()
AsyncConnection.close_on_internal_error()
AsyncConnection.close_socket()
AsyncConnection.create_stream()
AsyncConnection.from_socket()
AsyncConnection.process_next_frame()
AsyncConnection.send_frame()
AsyncConnection.start()
AsyncConnection.update_server_settings()
AsyncConnection.update_settings()
Connection
Connection.close()
Connection.close_on_error()
Connection.close_on_internal_error()
Connection.close_socket()
Connection.create_stream()
Connection.from_socket()
Connection.process_next_frame()
Connection.send_frame()
Connection.start()
Connection.update_server_settings()
Connection.update_settings()
async_initiate_connection()
async_start_connection()
initiate_connection()
start_connection()
- httpy.http2.error module
CANCEL
COMPRESSION_ERROR
CONNECT_ERROR
ENHANCE_YOUR_CALM
ErrType
FLOW_CONTROL_ERROR
FRAME_SIZE_ERROR
HTTP2Error
HTTP_1_1_REQUIRED
INADEQUATE_SECURITY
INTERNAL_ERROR
InvalidStreamID
NO_ERROR
PROTOCOL_ERROR
PayloadOverflow
REFUSED_STREAM
Refuse
SETTINGS_TIMEOUT
STREAM_CLOSED
UNKNOWN_ERROR
async_throw()
throw()
- httpy.http2.frame module
- httpy.http2.frame_queue module
- httpy.http2.priority module
- httpy.http2.proto module
- httpy.http2.settings module
- httpy.http2.socket_reader module
- httpy.http2.stream module
- httpy.http2.streams module
- httpy.http2.window module
- Module contents
Submodules
httpy.alpn module
- httpy.alpn.alpn_negotiate(sock, context, host)
httpy.debugger module
- httpy.debugger.get_path()
httpy.errors module
- exception httpy.errors.AuthError
Bases:
HTTPyError
Error in authentication
- exception httpy.errors.ClientError
Bases:
StatusError
Raised if server responded with 4xx status code
- exception httpy.errors.ConnectionClosedError
Bases:
HTTPyError
,ConnectionError
Connection Closed
- exception httpy.errors.ConnectionExpiredError
Bases:
HTTPyError
,ConnectionError
,TimeoutError
Connection Expired
- exception httpy.errors.ConnectionLimitError
Bases:
HTTPyError
,ConnectionError
Connection Limit reached
- exception httpy.errors.ContentTypeError
Bases:
HTTPyError
Raised if content type of resource does not match the desired operation
- exception httpy.errors.DeadConnectionError
Bases:
HTTPyError
,ConnectionError
Raised if the server didn’t respond to the request
- exception httpy.errors.HTTPyError
Bases:
Exception
A metaclass for all HTTPy Exceptions.
- exception httpy.errors.OldCacheFileWarning
Bases:
UserWarning
Raised when the cache file has an old version
- exception httpy.errors.ServerError
Bases:
StatusError
Raised if server is not found or if it responded with 5xx code
- exception httpy.errors.StatusError
Bases:
HTTPyError
Metaclass for ClientError and Server Error
- exception httpy.errors.TooManyRedirectsError
Bases:
HTTPyError
Raised if server responded with too many redirects (over redirection limit)
- exception httpy.errors.WebSocketClientError
Bases:
WebSocketError
Raised on erroneous close code
- exception httpy.errors.WebSocketError
Bases:
HTTPyError
Metaclass for exceptions in websockets
- exception httpy.errors.WebSocketHandshakeError
Bases:
WebSocketError
Raised upon a failed handshake
httpy.httpy module
HTTPy is a lightweight socket-based HTTP and WebSocket client.
- class httpy.httpy.AsyncProtoVersion
Bases:
object
- async recv_response(sock, *args)
- async send_request(sock, *args)
- class httpy.httpy.Cache(d=PosixPath('/home/docs/.cache/httpy/default/sites'))
Bases:
object
Cache Class
- updateCache()
Updates self.files according to /sites directory content and removes expired ones
- class httpy.httpy.CacheControl(directives)
Bases:
object
Class for parsing Cache-Control HTTP Headers
- class httpy.httpy.CacheFile(f)
Bases:
object
HTTPy cache file parser
- add_header(headers)
Adds If-None-Match and If-Modified-Since headers to request.
- Parameters:
headers – Headers to add into
- property expired
- class httpy.httpy.Connection(sock, timeout=inf, max=inf, is_http2=False)
Bases:
object
Class for connnections
- close()
- property sock
- class httpy.httpy.Cookie(name, value, attributes, host)
Bases:
object
Class for HTTP cookies
- as_header()
Returns Set-Cookie Header
- property expired
Checks if cookie expired
- classmethod from_binary(binary, host)
Creates cookie from binary representation
- classmethod from_header(header, host)
Parses cookie header
- to_binary()
Converts cookie to binary representation
- class httpy.httpy.CookieDomain(content, jar)
Bases:
object
Class for domain that stores cookies
- add_cookie(header)
Adds cookie from header to domain
- as_binary()
Returns binary representation for domain
- check_expired()
Checks for expired cookies and deletes them
- delete_cookie(key)
Deletes cookie from domain
- class httpy.httpy.CookieJar(jarfile=PosixPath('/home/docs/.cache/httpy/default/cj'))
Bases:
object
Class for cookie jars
- add_domain(name)
Adds domain to jar
- get_cookies(host, scheme, path)
Gets cookies for request
- update()
Updates jar file with domains
- class httpy.httpy.ETag(s)
Bases:
object
Class for HTTP ETags
- add_header(headers)
Appends this ETag in If-None-Match header.
- class httpy.httpy.File(buffer, filename, content_type=None)
Bases:
IOBase
Class used to upload files
- classmethod open(file)
- read(size=-1)
- save(destination)
- seek(pos)
Change the stream position to the given byte offset.
- offset
The stream position, relative to ‘whence’.
- whence
The relative position to seek from.
The offset is interpreted relative to the position indicated by whence. Values for whence are:
os.SEEK_SET or 0 – start of stream (the default); offset should be zero or positive
os.SEEK_CUR or 1 – current stream position; offset may be negative
os.SEEK_END or 2 – end of stream; offset is usually negative
Return the new absolute position.
- tell()
Return current stream position.
- value()
- write(anything)
- class httpy.httpy.HTTP11
Bases:
ProtoVersion
A sender/receiver for HTTP/1.1 requests
- recver = <httpy.httpy.HTTP11Recver object>
- sender
alias of
HTTP11Sender
- version = '1.1'
- class httpy.httpy.HTTP11Recver
Bases:
object
- class httpy.httpy.HTTP2
Bases:
ProtoVersion
A sender/receiver for synchronous HTTP/2 requests
- recver = <httpy.http2.proto.HTTP2Recver object>
- sender
alias of
HTTP2Sender
- version = '2'
- class httpy.httpy.Headers(h)
Bases:
CaseInsensitiveDict
Class for HTTP headers
- class httpy.httpy.KeepAlive(header)
Bases:
object
Class for parsing keep-alive headers
- class httpy.httpy.NonceCounter
Bases:
object
nonce use counter, used to get nc parameter in digest auth
- class httpy.httpy.PendingRequest(url, **kwargs)
Bases:
object
- property empty
- property finished
- property response
- wait()
- class httpy.httpy.PickleFile(fn)
Bases:
dict
- update([E, ]**F) None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- class httpy.httpy.ProtoVersion
Bases:
object
- recv_response(sock, *args)
- send_request(sock, *args)
- class httpy.httpy.Request(url, headers, method, socket, cache, http_version)
Bases:
object
- async async_perform()
- perform(enable_cache=False)
- class httpy.httpy.Response(method, status, headers, content, history, url, fromcache, original_content, request, time_elapsed=inf, cache=True, base_dir=PosixPath('/home/docs/.cache/httpy/default'))
Bases:
object
Class for HTTP Response.
- Parameters:
status (Status) – Status returned by server
headers (Headers) – Headers attached to the document
content (bytes) – Document content
history (list) – Response history
fromcache (bool) – Indicates whether or not was response loaded from cache
request (Request) – The Request object for this response
original_content (bytes) – Document content before any Content-Encoding was applied.
time_elapsed (float) – Total request time
- Variables:
status – Status returned by server
headers – Headers attached to the document
content – Document content
history – Response history
fromcache – Indicates whether or not was response loaded from cache
charset – Document charset
speed – Average download speed in bytes per second
request – The Request object for this response
method – Indicates HTTP method used to request
ok – self.status==200
- classmethod cacheload(cache_file)
Loads response from CacheFile.
- Parameters:
cache_file (CacheFile) – CacheFile to load from
- property charset
- property json
- classmethod plain()
- property string
- class httpy.httpy.Session
Bases:
object
Class for connection sessions
- async async_request(*args, **kwargs)
- close()
- async initiate_http2_connection(*args, **kwargs)
- request(*args, **kwargs)
- class httpy.httpy.WWW_Authenticate(header)
Bases:
object
Class for parsing WWW-Authenticate headers
- basic_auth(user, password)
- digest_auth(user, password, path, method, original)
- encode_password(user, password, path='/', method='GET', original=b'', decoded=b'')
- class httpy.httpy.WebSocket(url, mode='', debug=False, use_tls=None, subprotocol=None, origin=None)
Bases:
object
- close()
Closes the WebSocket connection with close code of 1000
- close_with_errcode(close_code, message)
- makefile()
- reconnect()
- recv()
Receives data from WebSocket server
- send(data)
Sends data to WebSocket server
- Parameters:
data (str or bytes) – Data to send to the server
- class httpy.httpy.WebSocketFile(websocket)
Bases:
object
WebSocket file class
- close()
Closes the Websocket
- read(b=None)
Reads from the Websocket :param b: Number of bytes to read. If None - reads until the end of buffer(if the buffer is empty, reads entire new frame) :type b:int or None
- seek(position)
Moves the cursor to a different position
- tell()
Returns the cursor position
- write(what)
Writes to the WebSocket
- httpy.httpy.absolute_path(url, last_url, scheme, host)
Makes relative urls absolute
- async httpy.httpy.async_request(url, *, session=<httpy.httpy.Session object>, method='GET', headers={}, body=b'', auth=(), redirlimit=20, content_type=None, timeout=30, history=None, throw_on_error=False, debug=False, pure_headers=False, enable_cache=True, base_dir=PosixPath('/home/docs/.cache/httpy/default'), http_version='2', disabled_headers=[], force_keep_alive=False, enable_cookies=True)
Performs an asynchronous request. Asynchronous requests are always HTTP/2.
Note: all arguments but
url
are keyword-only- Parameters:
url (
str
) – url to requestmethod (
str
) – method to use, defaults to"GET"
headers (
dict
) – headers to add to the request, defaults to{}
body – request body, can be
bytes
,str
ordict
, defaults tob''
auth (
tuple
) – credentials to use ({"username":"password"}
), defaults to{}
redirlimit (
int
) – redirect limit . If number of redirects has reachedredirlimit
,TooManyRedirectsError
will be raised. Defaults to20
.content_type – content type of request body, defaults to
None
timeout (
int
) – request timeout, defaults to30
history – request history, defaults to
None
throw_on_error – if throw_on_error is
True
, StatusError will be raised if server responded with 4xx or 5xx status code.debug (
bool
) – whether or not shall debug mode be used , defaults toFalse
base_dir (
pathlib.Path
) – HTTPy cache directory to use for the request, default is"~/.cache/httpy/default"
http_version – HTTP version to use, MUST be “2”. For async http/1 requests use aiohttp or the blocking parameter of request() for requests in a separate thread
disabled_headers (
list
) – Disable selected headers.force_keep_alive – If
False
, request will be retried upon connection being closed if the connection is in keep-alive mode.
:type force_keep_alive:
bool
- httpy.httpy.cacheWrite(response, base_dir, expires_override=None)
Writes response to cache
- Parameters:
response (Response) – response to save
- httpy.httpy.close_all()
Closes all sessions. Always called at program exit.
- async httpy.httpy.create_async_h2_connection(host, port, last_response, http_version, scheme, session)
- httpy.httpy.create_connection(host, port, last_response, http_version, scheme, do_keep_alive, session)
Creates a connection to a given host and port
- httpy.httpy.deslash(url)
Removes trailing slash from the end of URL
- httpy.httpy.determine_charset(headers)
Gets charset from headers
- httpy.httpy.dir_count()
- httpy.httpy.encode_form_data(data, content_type=None)
Encodes form data according to content type
- httpy.httpy.find_dir_by_id(sessid)
- httpy.httpy.generate_cnonce(length=16)
- httpy.httpy.generate_dir_id()
- httpy.httpy.generate_websocket_key()
Generates a websocket key
- httpy.httpy.get_connection(host, port)
Returns a connection in the default session.
- httpy.httpy.get_content_type(data)
Used to automatically get request content type
- httpy.httpy.hashing_function(function_name)
- async httpy.httpy.initiate_http2_connection(url=None, host=None, session=<httpy.httpy.Session object>)
Starts a HTTP/2 connection and adds it to a session. Used to send multiple asynchronous requests on one connection.
- httpy.httpy.makehost(host, port)
Creates hostname from host and port
- httpy.httpy.md5()
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- httpy.httpy.mkdict(kvp)
Makes dict from key/value pairs
- httpy.httpy.multipart(form, boundary=b'--uLBs7UyEb8\r\n')
Builds multipart/form-data from form
- httpy.httpy.request(url, *, session=<httpy.httpy.Session object>, method='GET', headers={}, body=b'', auth=(), redirlimit=20, content_type=None, timeout=30, history=None, throw_on_error=False, debug=False, pure_headers=False, enable_cache=True, base_dir=PosixPath('/home/docs/.cache/httpy/default'), http_version=None, disabled_headers=[], blocking=True, force_keep_alive=False, enable_cookies=True)
Performs request.
Note: all arguments but
url
are keyword-only- Parameters:
url (
str
) – url to requestmethod (
str
) – method to use, defaults to"GET"
headers (
dict
) – headers to add to the request, defaults to{}
body – request body, can be
bytes
,str
ordict
, defaults tob''
auth (
tuple
) – credentials to use ({"username":"password"}
), defaults to{}
redirlimit (
int
) – redirect limit . If number of redirects has reachedredirlimit
,TooManyRedirectsError
will be raised. Defaults to20
.content_type – content type of request body, defaults to
None
timeout (
int
) – request timeout, defaults to30
history – request history, defaults to
None
throw_on_error – if throw_on_error is
True
, StatusError will be raised if server responded with 4xx or 5xx status code.debug (
bool
) – whether or not shall debug mode be used , defaults toFalse
base_dir (
pathlib.Path
) – HTTPy cache directory to use for the request, default is"~/.cache/httpy/default"
http_version – HTTP version to use, MUST be “1.1” or “2” or None. If None the HTTP version will be automatically detected via ALPN.
disabled_headers (
list
) – Disable selected headers.blocking (
bool
) – IfFalse
, request is performed in a separate thread. Defaults toTrue
force_keep_alive – If
False
, request will be retried upon connection being closed if the connection is in keep-alive mode.
:type force_keep_alive:
bool
- httpy.httpy.reslash(url)
Adds trailing slash to the end of URL
- httpy.httpy.set_debug(d=True)
- httpy.httpy.setup_dir(dir_path, name)
- httpy.httpy.sha1()
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- httpy.httpy.sha256()
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- httpy.httpy.sha512()
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- httpy.httpy.urlencode(data)
Creates urlencoded string from dict data
- httpy.httpy.websocket_handshake(url, key, cdebugger, subprotocol=None, origin=None, additional_headers={})
Performs a WebSocket Handshake
- Parameters:
url (str) – url to send request to
key (str) – WebSocket secret key
subprotocol (str or None) – Subprotocol to use, defaults to None
origin (str or None) – Origin of request, defaults to None
additional_headers (dict) – Additional headers to send request with, defaults to {}
httpy.patterns module
httpy.status module
- class httpy.status.Status(statstring)
Bases:
int
Creates HTTP status from string.
- Parameters:
statstring – string to parse
- httpy.status.status_from_int(stat)
httpy.utils module
- class httpy.utils.CaseInsensitiveDict(data)
Bases:
dict
Case insensitive subclass of dictionary that supports multiple values for a single key
- get(key, default=None)
Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- update([E, ]**F) None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values
- httpy.utils.byte_length(i)
- httpy.utils.capitalize(string)
- httpy.utils.decode_content(content, encoding)
Decodes content with get_encoding_chain()
- httpy.utils.force_bytes(anything)
Converts bytes or string to bytes
- httpy.utils.force_string(anything)
Converts string or bytes to string
- httpy.utils.get_host(url)
- httpy.utils.getbytes(bits)
- httpy.utils.int2bytes(i, bl=None)
- httpy.utils.mask(data, mask)
- httpy.utils.mk_header(key_value_pair)
Makes header from key/value pair
- httpy.utils.mkbits(i, pad=None)
- httpy.utils.read_until(fp, token)