Skip to content

sok.apis.base_api

Base API client implementation.

Provides the foundational BaseAPI class that all media API clients inherit from. Handles HTTP session management, request lifecycle, and connection pooling.

BaseAPI

class BaseAPI(api_key: str, base_url: str)

Bases: MediaAPI

Common base class for all API implementations.

Provides shared functionality for HTTP requests, session management, and connection handling. All specific API implementations should inherit from this class.

Initialize the API client.

Parameters

NameTypeDescription
api_keystrAPI authentication key.
base_urlstrBase URL for all API requests.
Source

Attributes

NameTypeDescription
api_keystr

API authentication key.

base_urlstr

Base URL for API requests.

api_nameproperty

str

Name of the service in error messages, from the class name.

sessionpropertywritable

Optional[aiohttp.ClientSession]

The HTTP session of the running event loop, or None.

closeasync

async def close() -> None:

Close the aiohttp session of the running event loop.

The sessions of other loops belong to other workers and are left alone. Safe to call multiple times. Errors during close are silently ignored.

Source

Functions

close_loop_sessionsasync

async def close_loop_sessions() -> None:

Close the sessions every API client opened in the running event loop.

A search worker calls it before closing its loop, so no session is left open on a loop that is gone.

Source
Built with Kiln