pycivitai.client.http

get_session

pycivitai.client.http.get_session() Session[source]

Get a requests.Session object, using the session factory from the user.

Use [get_session] to get a configured Session. Since requests.Session is not guaranteed to be thread-safe, huggingface_hub creates 1 Session instance per thread. They are all instantiated using the same backend_factory set in [configure_http_backend]. A LRU cache is used to cache the created sessions (and connections) between calls. Max size is 128 to avoid memory leaks if thousands of threads are spawned.

See [this issue](https://github.com/psf/requests/issues/2766) to know more about thread-safety in requests.

Example: ```py import requests from huggingface_hub import configure_http_backend, get_session

# Create a factory function that returns a Session with configured proxies def backend_factory() -> requests.Session:

session = requests.Session() session.proxies = {“http”: “http://10.10.1.10:3128”, “https”: “https://10.10.1.11:1080”} return session

# Set it as the default session factory configure_http_backend(backend_factory=backend_factory)

# In practice, this is mostly done internally in huggingface_hub session = get_session() ```

configure_http_backend

pycivitai.client.http.configure_http_backend(backend_factory: ~typing.Callable[[], ~requests.Session] = <class 'requests.Session'>) None[source]

Configure the HTTP backend by providing a backend_factory. Any HTTP calls made by huggingface_hub will use a Session object instantiated by this factory. This can be useful if you are running your scripts in a specific environment requiring custom configuration (e.g. custom proxy or certifications).

Use [get_session] to get a configured Session. Since requests.Session is not guaranteed to be thread-safe, huggingface_hub creates 1 Session instance per thread. They are all instantiated using the same backend_factory set in [configure_http_backend]. A LRU cache is used to cache the created sessions (and connections) between calls. Max size is 128 to avoid memory leaks if thousands of threads are spawned.

See [this issue](https://github.com/psf/requests/issues/2766) to know more about thread-safety in requests.

Example: ```py import requests from huggingface_hub import configure_http_backend, get_session

# Create a factory function that returns a Session with configured proxies def backend_factory() -> requests.Session:

session = requests.Session() session.proxies = {“http”: “http://10.10.1.10:3128”, “https”: “https://10.10.1.11:1080”} return session

# Set it as the default session factory configure_http_backend(backend_factory=backend_factory)

# In practice, this is mostly done internally in huggingface_hub session = get_session() ```

ENDPOINT

pycivitai.client.http.ENDPOINT = 'https://civitai.com'

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’.

OFFLINE_MODE

pycivitai.client.http.OFFLINE_MODE = False

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

OfflineModeEnabled

exception pycivitai.client.http.OfflineModeEnabled[source]