Skip to content

Transports

UrllibTransport

UrllibTransport(
    *,
    timeout: float = DEFAULT_TIMEOUT,
    retries: int = 2,
    backoff: float = 0.5,
    opener: OpenerDirector | None = None,
    headers: Mapping[str, str] | None = None,
)

The default transport. Uses only the Python standard library.

A request that fails with a network error, a timeout or a 429, 502, 503 or 504 status is tried again up to retries times. It waits backoff seconds before the first retry and twice as long before each one after. A failed TLS certificate check is not retried.

Proxies set in the environment (HTTPS_PROXY) are used automatically. Pass your own urllib.request opener for other connection settings, and headers to send extra headers with every request.

close

close() -> None

Release what the transport holds open. Does nothing by default.

Transport

Fetches URLs for the client.

Subclass it to use another HTTP library, or to add retries, caching or rate limiting. Only get is required:

class HttpxTransport(Transport):
    def __init__(self):
        self.client = httpx.Client()

    def get(self, url):
        response = self.client.get(url)
        return Response(response.status_code, response.content)

get

get(url: str) -> Response

Fetch a URL and return the response, whatever its status.

Raise TransportError if no response arrives.

stream_lines

stream_lines(url: str) -> Generator[str, None, None]

Yield the lines of a large text download, without line endings.

This default loads the whole body first. Override it to stream. Raise APIError if the status is not a success.

close

close() -> None

Release what the transport holds open. Does nothing by default.

AsyncTransport

Fetches URLs for the async client.

Subclass it to use an async HTTP library. Only get is required:

class HttpxTransport(AsyncTransport):
    def __init__(self):
        self.client = httpx.AsyncClient()

    async def get(self, url):
        response = await self.client.get(url)
        return Response(response.status_code, response.content)

get

get(url: str) -> Response

Fetch a URL and return the response, whatever its status.

Raise TransportError if no response arrives.

stream_lines

stream_lines(url: str) -> AsyncGenerator[str, None]

Yield the lines of a large text download, without line endings.

This default loads the whole body first. Override it to stream. Raise APIError if the status is not a success.

aclose

aclose() -> None

Release what the transport holds open. Does nothing by default.

ThreadedTransport

ThreadedTransport(
    transport: Transport | None = None,
    *,
    batch_size: int = 5000,
)

Makes a blocking transport usable from async code.

Each request runs in a worker thread, so the event loop is never blocked.

Response

Response(status: int, body: bytes = b'')

What a transport returns: the HTTP status and the raw body.

json

json() -> Any

Decode the body as JSON. Raises EUVDError if it is not JSON.

raise_for_status

raise_for_status() -> None

Raise NotFoundError or APIError if the status is not a success.