Skip to main content

Asyncly

PyPI version Python versions License Documentation

A tiny async HTTP client and a real aiohttp mock server for testing your integrations — built on aiohttp.

asyncly gives you two pieces that fit together:

  • BaseHttpClient — a thin, typed base class for HTTP clients with per-status response handlers, policy-driven retries, flexible timeouts, and first-class proxy support. InstrumentableHttpClient adds pluggable metrics (Prometheus / OpenTelemetry): requests, in-flight, network phases, and connection-pool stats.
  • srvmocker — spin up a real aiohttp test server (not a transport patch) to simulate upstreams and socket faults, assert what your client sent, and even route through a mock proxy.

📖 Read the full documentation →

Installation

pip install asyncly

Optional extras — msgspec, pydantic, orjson, prometheus, opentelemetry:

pip install "asyncly[pydantic]"

Quickstart

Define a client by subclassing BaseHttpClient and mapping status codes to handlers:

from http import HTTPStatus
from types import MappingProxyType

from aiohttp import ClientSession, hdrs
from pydantic import BaseModel

from asyncly import BaseHttpClient, DEFAULT_TIMEOUT, ResponseHandlersType
from asyncly.client.handlers.pydantic import parse_model
from asyncly.client.timeout import TimeoutType


class CatFact(BaseModel):
    fact: str
    length: int


class CatfactClient(BaseHttpClient):
    FACT_HANDLERS: ResponseHandlersType = MappingProxyType(
        {HTTPStatus.OK: parse_model(CatFact)}
    )

    async def fetch_fact(self, timeout: TimeoutType = DEFAULT_TIMEOUT) -> CatFact:
        return await self._make_req(
            method=hdrs.METH_GET,
            url=self._url / "fact",
            handlers=self.FACT_HANDLERS,
            timeout=timeout,
        )

Test it against a real mock server — no network, no monkeypatching:

from asyncly.srvmocker import JsonResponse, MockRoute, start_service


async def test_fetch_fact() -> None:
    routes = [MockRoute("GET", "/fact", "fact")]
    async with start_service(routes) as service:
        service.register("fact", JsonResponse({"fact": "Cats sleep a lot.", "length": 17}))

        async with ClientSession() as session:
            client = CatfactClient(url=service.url, session=session, client_name="catfact")
            fact = await client.fetch_fact()

        assert fact.fact == "Cats sleep a lot."
        service.assert_called("fact", times=1)

Prefer fixtures over boilerplate? asyncly ships a pytest plugin with mock_service and mock_proxy. See the Quickstart for more.

Why asyncly?

Unlike transport-patching mocks (aioresponses, respx), srvmocker runs a real aiohttp.TestServer inside your test loop — catching real sockets, timeouts, header auto-injection, and serialization quirks. See Testing strategies for the full comparison.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncly-0.10.0.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asyncly-0.10.0-py3-none-any.whl (48.0 kB view details)

Uploaded Python 3

File details

Details for the file asyncly-0.10.0.tar.gz.

File metadata

  • Download URL: asyncly-0.10.0.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for asyncly-0.10.0.tar.gz
Algorithm Hash digest
SHA256 c07ca5621db6a1eb66e248158232f4c468032dce96d9b8e1bd90f0e958b7ed7b
MD5 a581437c6238951532d883b3a01cfe0d
BLAKE2b-256 5aed62b0f88beaae362b5f8760acc53cbb946e33601d8a1818a4189960c5b730

See more details on using hashes here.

File details

Details for the file asyncly-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: asyncly-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 48.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for asyncly-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3862cf08891db81143f008b4c333f9ace5882ecac8a58b23985a8fad5c177610
MD5 ea9e79540139078b2dfb8aedd6ef9202
BLAKE2b-256 c80a7c9740ae51fd341505ab03ac059b7dc8f63983106231b9f989f0bd731846

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page