Simple HTTP client and server for your integrations based on aiohttp
Project description
Asyncly
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, flexible timeouts, and first-class proxy support.srvmocker— spin up a real aiohttp test server (not a transport patch) to simulate upstreams in tests, 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asyncly-0.7.1.tar.gz.
File metadata
- Download URL: asyncly-0.7.1.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db9b1211bf55da0504d7f4c0e6f062ef46dcdd434c3881fb371e020acfdf16a5
|
|
| MD5 |
09e28d066623877d9473121aed24c05d
|
|
| BLAKE2b-256 |
4520736298f49feb67399c5352e640c4702853744a5d410aa2bfbe7647582884
|
File details
Details for the file asyncly-0.7.1-py3-none-any.whl.
File metadata
- Download URL: asyncly-0.7.1-py3-none-any.whl
- Upload date:
- Size: 33.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
beade1d0f35aa52ebc9fdf4e18e02301d7ded3f14af545e94bbf7e1fa84e0f19
|
|
| MD5 |
d7af5b3d0b757fbc1a78ed515cf51881
|
|
| BLAKE2b-256 |
d64a06e3448abf981faf10baba963402c29c1cc69808d5cfd001e8bfb0ae22fa
|