hibachi.session
Documentation for eth_defi.hibachi.session Python module.
HTTP session management for Hibachi API.
This module provides session creation with retry logic for Hibachi API requests.
The HibachiSession carries the API URL so that downstream
functions do not need a separate api_url argument.
No rate limiting is applied — the data-api.hibachi.xyz endpoint
has not shown any rate limiting behaviour.
Functions
|
Create a |
Classes
A |
- class HibachiSession
Bases:
requests.sessions.SessionA
requests.Sessionsubclass that carries the Hibachi API URL.All Hibachi API functions accept a
HibachiSessionand readapi_urlfrom it, removing the need for a separateapi_urlargument on every call.Use
create_hibachi_session()to create instances.- close()
Closes all adapters and as such the session
- delete(url, **kwargs)
Sends a DELETE request. Returns
Responseobject.- Parameters
url – URL for the new
Requestobject.**kwargs – Optional arguments that
requesttakes.
- Return type
requests.Response
- get(url, **kwargs)
Sends a GET request. Returns
Responseobject.- Parameters
url – URL for the new
Requestobject.**kwargs – Optional arguments that
requesttakes.
- Return type
requests.Response
- get_adapter(url)
Returns the appropriate connection adapter for the given URL.
- Return type
requests.adapters.BaseAdapter
- get_redirect_target(resp)
Receives a Response. Returns a redirect URI or
None
- head(url, **kwargs)
Sends a HEAD request. Returns
Responseobject.- Parameters
url – URL for the new
Requestobject.**kwargs – Optional arguments that
requesttakes.
- Return type
requests.Response
- merge_environment_settings(url, proxies, stream, verify, cert)
Check the environment and merge it with some settings.
- Return type
- mount(prefix, adapter)
Registers a connection adapter to a prefix.
Adapters are sorted in descending order by prefix length.
- options(url, **kwargs)
Sends a OPTIONS request. Returns
Responseobject.- Parameters
url – URL for the new
Requestobject.**kwargs – Optional arguments that
requesttakes.
- Return type
requests.Response
- patch(url, data=None, **kwargs)
Sends a PATCH request. Returns
Responseobject.- Parameters
url – URL for the new
Requestobject.data – (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the
Request.**kwargs – Optional arguments that
requesttakes.
- Return type
requests.Response
- post(url, data=None, json=None, **kwargs)
Sends a POST request. Returns
Responseobject.- Parameters
url – URL for the new
Requestobject.data – (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the
Request.json – (optional) json to send in the body of the
Request.**kwargs – Optional arguments that
requesttakes.
- Return type
requests.Response
- prepare_request(request)
Constructs a
PreparedRequestfor transmission and returns it. ThePreparedRequesthas settings merged from theRequestinstance and those of theSession.- Parameters
request –
Requestinstance to prepare with this session’s settings.- Return type
requests.PreparedRequest
- put(url, data=None, **kwargs)
Sends a PUT request. Returns
Responseobject.- Parameters
url – URL for the new
Requestobject.data – (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the
Request.**kwargs – Optional arguments that
requesttakes.
- Return type
requests.Response
- rebuild_auth(prepared_request, response)
When being redirected we may want to strip authentication from the request to avoid leaking credentials. This method intelligently removes and reapplies authentication where possible to avoid credential loss.
- rebuild_method(prepared_request, response)
When being redirected we may want to change the method of the request based on certain specs or browser behavior.
- rebuild_proxies(prepared_request, proxies)
This method re-evaluates the proxy configuration by considering the environment variables. If we are redirected to a URL covered by NO_PROXY, we strip the proxy configuration. Otherwise, we set missing proxy keys for this URL (in case they were stripped by a previous redirect).
This method also replaces the Proxy-Authorization header where necessary.
- Return type
- request(method, url, params=None, data=None, headers=None, cookies=None, files=None, auth=None, timeout=None, allow_redirects=True, proxies=None, hooks=None, stream=None, verify=None, cert=None, json=None)
Constructs a
Request, prepares it and sends it. ReturnsResponseobject.- Parameters
method – method for the new
Requestobject.url – URL for the new
Requestobject.params – (optional) Dictionary or bytes to be sent in the query string for the
Request.data – (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the
Request.json – (optional) json to send in the body of the
Request.headers – (optional) Dictionary of HTTP Headers to send with the
Request.cookies – (optional) Dict or CookieJar object to send with the
Request.files – (optional) Dictionary of
'filename': file-like-objectsfor multipart encoding upload.auth – (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth.
timeout (float or tuple) – (optional) How many seconds to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) tuple.
allow_redirects (bool) – (optional) Set to True by default.
proxies – (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy.
hooks – (optional) Dictionary mapping hook name to one event or list of events, event must be callable.
stream – (optional) whether to immediately download the response content. Defaults to
False.verify – (optional) Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to
True. When set toFalse, requests will accept any TLS certificate presented by the server, and will ignore hostname mismatches and/or expired certificates, which will make your application vulnerable to man-in-the-middle (MitM) attacks. Setting verify toFalsemay be useful during local development or testing.cert – (optional) if String, path to ssl client cert file (.pem). If Tuple, (‘cert’, ‘key’) pair.
- Return type
requests.Response
- resolve_redirects(resp, req, stream=False, timeout=None, verify=True, cert=None, proxies=None, yield_requests=False, **adapter_kwargs)
Receives a Response. Returns a generator of Responses or Requests.
- send(request, **kwargs)
Send a given PreparedRequest.
- Return type
requests.Response
- should_strip_auth(old_url, new_url)
Decide whether Authorization header should be removed when redirecting
- create_hibachi_session(api_url='https://data-api.hibachi.xyz', retries=5, backoff_factor=0.5)
Create a
HibachiSessionconfigured for Hibachi API.The session is configured with retry logic for handling transient errors using exponential backoff. No rate limiting is applied — the Hibachi data API has not shown rate limiting behaviour.
Example:
from eth_defi.hibachi.session import create_hibachi_session session = create_hibachi_session()
- Parameters
api_url (str) – Hibachi data API base URL. Defaults to
HIBACHI_DATA_API_URL.retries (int) – Maximum number of retry attempts for failed requests.
backoff_factor (float) – Backoff factor for exponential retry delays.
- Returns
Configured
HibachiSessionwith retry logic.- Return type