httpy package
Subpackages
- httpy.http2 package
- Subpackages
- Submodules
- httpy.http2.connection module
AsyncConnectionAsyncConnection.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()
ConnectionConnection.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
CANCELCOMPRESSION_ERRORCONNECT_ERRORENHANCE_YOUR_CALMErrTypeFLOW_CONTROL_ERRORFRAME_SIZE_ERRORHTTP2ErrorHTTP_1_1_REQUIREDINADEQUATE_SECURITYINTERNAL_ERRORInvalidStreamIDNO_ERRORPROTOCOL_ERRORPayloadOverflowREFUSED_STREAMRefuseSETTINGS_TIMEOUTSTREAM_CLOSEDUNKNOWN_ERRORasync_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:
HTTPyErrorError in authentication
- exception httpy.errors.ClientError
Bases:
StatusErrorRaised if server responded with 4xx status code
- exception httpy.errors.ConnectionClosedError
Bases:
HTTPyError,ConnectionErrorConnection Closed
- exception httpy.errors.ConnectionExpiredError
Bases:
HTTPyError,ConnectionError,TimeoutErrorConnection Expired
- exception httpy.errors.ConnectionLimitError
Bases:
HTTPyError,ConnectionErrorConnection Limit reached
- exception httpy.errors.ContentTypeError
Bases:
HTTPyErrorRaised if content type of resource does not match the desired operation
- exception httpy.errors.DeadConnectionError
Bases:
HTTPyError,ConnectionErrorRaised if the server didn’t respond to the request
- exception httpy.errors.HTTPyError
Bases:
ExceptionA metaclass for all HTTPy Exceptions.
- exception httpy.errors.OldCacheFileWarning
Bases:
UserWarningRaised when the cache file has an old version
- exception httpy.errors.ServerError
Bases:
StatusErrorRaised if server is not found or if it responded with 5xx code
- exception httpy.errors.StatusError
Bases:
HTTPyErrorMetaclass for ClientError and Server Error
- exception httpy.errors.TooManyRedirectsError
Bases:
HTTPyErrorRaised if server responded with too many redirects (over redirection limit)
- exception httpy.errors.WebSocketClientError
Bases:
WebSocketErrorRaised on erroneous close code
- exception httpy.errors.WebSocketError
Bases:
HTTPyErrorMetaclass for exceptions in websockets
- exception httpy.errors.WebSocketHandshakeError
Bases:
WebSocketErrorRaised upon a failed handshake
httpy.httpy module
HTTPy is a lightweight socket-based HTTP and WebSocket client.
- class httpy.httpy.Connection(sock, timeout=inf, max=inf, is_http2=False)
Bases:
objectClass for connnections
- close()
- property sock
- class httpy.httpy.Cookie(name, value, attributes, host)
Bases:
objectClass 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:
objectClass 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:
objectClass 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.KeepAlive(header)
Bases:
objectClass for parsing keep-alive headers
- class httpy.httpy.NonceCounter
Bases:
objectnonce 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.Request(url, headers, method, socket, cache, http_version)
Bases:
object- async async_perform()
- perform(enable_cache=False)
- class httpy.httpy.Session
Bases:
objectClass 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:
objectClass 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:
objectWebSocket 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=False, base_dir=PosixPath('/home/docs/.cache/httpy/default'), http_version='2', disabled_headers=[], force_keep_alive=False, enable_cookies=False, stream=False)
Performs an asynchronous request. Asynchronous requests are always HTTP/2.
Note: all arguments but
urlare 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,strordict, defaults tob''auth (
tuple) – credentials to use ({"username":"password"}), defaults to{}redirlimit (
int) – redirect limit . If number of redirects has reachedredirlimit,TooManyRedirectsErrorwill be raised. Defaults to20.content_type – content type of request body, defaults to
Nonetimeout (
int) – request timeout, defaults to30history – request history, defaults to
Nonethrow_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 toFalsebase_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.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, cert, verify, check_hostname)
Creates a connection to a given host and port
- httpy.httpy.create_socket(host, port, cert, verify, check_hostname, alpn_protocols, https)
- httpy.httpy.dir_count()
- httpy.httpy.find_dir_by_id(sessid, name)
- 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.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.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.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=False, base_dir=PosixPath('/home/docs/.cache/httpy/default'), http_version=None, disabled_headers=[], blocking=True, force_keep_alive=False, enable_cookies=False, stream=False, cert=None, verify=None, check_hostname=True)
Performs request.
Note: all arguments but
urlare 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,strordict, defaults tob''auth (
tuple) – credentials to use ({"username":"password"}), defaults to{}redirlimit (
int) – redirect limit . If number of redirects has reachedredirlimit,TooManyRedirectsErrorwill be raised. Defaults to20.content_type – content type of request body, defaults to
Nonetimeout (
int) – request timeout, defaults to30history – request history, defaults to
Nonethrow_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 toFalsebase_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 toTrueforce_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.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.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:
intCreates HTTP status from string.
- Parameters:
statstring – string to parse
- httpy.status.status_from_int(stat)
httpy.utils module
- class httpy.utils.CaseInsensitiveDict(data)
Bases:
dictCase 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
- class httpy.utils.File(buffer, filename, content_type=None)
Bases:
IOBaseClass 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)
- httpy.utils.byte_length(i)
- httpy.utils.capitalize(string)
- httpy.utils.decode_content(content, encoding)
Decodes content with get_encoding_chain()
- httpy.utils.deslash(url)
Removes trailing slash from the end of URL
- httpy.utils.determine_charset(headers)
Gets charset from headers
- httpy.utils.encode_form_data(data, content_type=None)
Encodes form data according to content type
- httpy.utils.force_bytes(anything)
Converts bytes or string to bytes
- httpy.utils.force_string(anything)
Converts string or bytes to string
- httpy.utils.generate_cnonce(length=16)
- httpy.utils.get_content_type(data)
Used to automatically get request content type
- httpy.utils.get_host(url)
- httpy.utils.getbytes(bits)
- httpy.utils.int2bytes(i, bl=None)
- httpy.utils.makehost(host, port)
Creates hostname from host and port
- 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.mkdict(kvp)
Makes dict from key/value pairs
- httpy.utils.multipart(form, boundary=None)
Builds multipart/form-data from form
- httpy.utils.read_until(fp, token)
- httpy.utils.reslash(url)
Adds trailing slash to the end of URL
- httpy.utils.urlencode(data)
Creates urlencoded string from dict data