Skip to main content

mimicry for Python

License CI PyPI Python

HTTP requests the way Chrome, Firefox, Safari, Edge and Brave send them (the TLS handshake, HTTP/2 and HTTP/3, the headers and their order, cookies and redirects), from Python. This is the Python SDK of mimicry, a Go library: each Python process starts its own mimicry-core, mimicry built as a small static program shipped inside the wheel, and talks to it over a socketpair (two anonymous pipes on Windows). Why it is built this way, and what was measured, is in decision 0069.

Python 3.11 or later, on Linux (glibc or musl), macOS 13 or later, and Windows; x86-64 and arm64. The one dependency is protobuf (6.30 or later). HTTPS needs the system's root certificates: a slim container image without them (/etc/ssl/certs missing) needs the ca-certificates package.

pip install mimicry-http

Quick start

import mimicry
from mimicry import Config, Kind, Request, profiles

client = mimicry.new_client(Config(profile=profiles.chrome_macos()))

# A plain request is a page load, as if typed into the address bar.
page = client.do(Request("GET", "https://www.shop.example/p/42"))
html = page.read()

# A fetch() from that page: Origin, Referer, sec-fetch-* and cookies follow.
api = Request("GET", "https://www.shop.example/api/stock/42")
resp = client.do(mimicry.as_kind(api, Kind.FETCH))

The same with asyncio, from mimicry.aio (every name is the same; the calls are awaited):

from mimicry import Config, Kind, Request, aio, as_kind, profiles


async def main() -> None:
    async with await aio.new_client(Config(profile=profiles.chrome_macos())) as client:
        page = await client.do(Request("GET", "https://www.shop.example/p/42"))
        html = await page.read()
        resp = await client.do(as_kind(Request("GET", "https://www.shop.example/api/stock/42"), Kind.FETCH))
        async for chunk in resp.aiter_bytes():
            ...

A request the profile can't describe fails with NotMeasuredError before anything is sent, rather than guessing.

Go's names

The SDK uses mimicry's Go names in Python casing, so the Go guides apply as they are. Three Go names are Python keywords or clash, and change:

Go Python
mimicry.NewClient(cfg), NewTransport(cfg) mimicry.new_client(config), new_transport(config)
client.Do(req), transport.RoundTrip(req) client.do(req), transport.round_trip(req)
mimicry.Config{DialTimeout: 10 * time.Second, DisableHTTP3: true} Config(dial_timeout=10, disable_http3=True) (durations in seconds or timedelta)
profiles.ChromeMacOS(), profiles.ByName("chrome-157-macos") profiles.chrome_macos() (the newest the core has), "chrome-157-macos"
mimicry.Fetch, AsyncScript, ... Kind.FETCH, Kind.ASYNC_SCRIPT, ...
mimicry.As(req, k) as_kind(req, k)
mimicry.With(req, mimicry.Request{From: page, Kind: k}) with_options(req, Options(page=page, kind=k))
mimicry.Exact(req), HeaderOrderKey exact(req), Request(..., header_order=[...])
Transport.Plan(req) client.plan(req) / transport.plan(req): what would be sent, str() is Go's Plan.String()
Transport.DialWebSocket(ctx, url, WebSocketOptions{From, Protocols}) client.dial_websocket(url, WebSocketOptions(page=, protocols=))
ws.ReadMessage, WriteMessage, Close(code, reason) ws.read_message(), write_message(MessageType.TEXT, data), close(code, reason)
jar.WriteJSON(w) / ReadJSON(r) (cookies.Jar, TicketCache, AltSvcCache, ClientHintStore) write_json(path_or_file) / read_json(path_or_file)
mimicry.NewTrafficMeter(TrafficOptions{ByHost: true}), meter.Snapshot() / Reset() new_traffic_meter(by_host=True), meter.snapshot() / reset(): a Traffic, its by_host a dict[Peer, Bytes]
context.Context Request(timeout=...), and asyncio cancellation

A Request is Request(method, url, headers=, body=, ...); headers is a mapping or (name, value) pairs, a value of None removing a header the profile would send (as an empty Go Header entry does). A body of bytes is sent whole and sent again on a redirect that keeps it; an iterable of bytes (an async iterable in the async API) is streamed, and cannot be.

Callbacks are data, as decision 0069 lists: proxy= (a URL, per client or per Request), connect_udp_proxy=, client_certificates= (PEM bytes per host), key_log_file=, dns_server=, follow_redirects=/max_redirects= on new_client. Two are callables:

  • Config(verify_connection=fn): fn(state: ConnectionState) sees each verified TLS connection; raising rejects it (the request fails with VerifyError). In the async API it may be a coroutine function. fetch_pins ignores it (and pins), as Go's FetchPins does.
  • new_jar(on_set_cookie=fn): fn(event: SetCookieEvent) for each Set-Cookie line the jar receives.

In the sync API both run on worker threads (never the SDK's own), so they may block and call the SDK.

Errors

Every exception is a MimicryError, with one class per kind of Go error: NotMeasuredError, CORSError, ProxyError, PinError, BlockedError, PlacementError, CloseError, ValidationError, CanceledError, DeadlineError, NetError, InvalidError, VerifyError, InternalError. Each carries code, message and matches, every kind its Go error chain matches (errors.Is/errors.As); the exception is an instance of each of them. A proxy that times out raises an error both except ProxyError and except DeadlineError catch. DeadlineError is also a TimeoutError, NetError a ConnectionError and InvalidError a ValueError. The typed fields are attributes: ProxyError.status_code, CORSError.reason, CloseError.close_code, PinError.host, ValidationError.problems.

If mimicry-core dies, every call on it raises CoreExited, with its exit status (returncode, negative for the signal that ended it) and the last of its stderr; its objects are gone. The next client made without an explicit core starts a new one. A broken connection with the core still running raises ProtocolError (and the core is stopped).

Processes, threads and asyncio

  • One core per process. The sync API's objects share one core, started on first use and driven by one background thread running an event loop; any number of threads may call them. The async API's objects use their event loop's core. A mimicry.Core / aio.AsyncCore you start yourself can be passed as core=.
  • fork. A forked child never touches its parent's core: the SDK drops the inherited connection in the child (os.register_at_fork), and the child's first new object starts the child's own core. Objects made before the fork (a client made at import in a gunicorn --preload app, say) raise MimicryError in the child: their state (cookies, tickets) lives in the parent's core. Make clients after the fork, or save state in the parent and load it in each child. In the child, use the async API from a new event loop (asyncio.run), as asyncio requires after a fork anyway.
  • Event loops. An async object belongs to the loop it was made on.
  • Cancellation. Canceling a call (task.cancel(), a timeout) resets it in the core. A WebSocket read canceled part way loses nothing (the next read returns the message), and a write canceled part way still sends its message whole.
  • Windows. The core's stdin and stdout are anonymous pipes driven by two threads, not socket.socketpair() (loopback TCP on Windows; decision 0069). Any event loop works.
  • Closing. close() (or with / async with) frees an object in the core; one collected unclosed is freed in the background, and a response collected unread cancels its request. Closing the core, or the process exiting, ends the core.

Saving an identity

Cookies, TLS session tickets, Alt-Svc records and client hints save and load as JSON, to carry an identity to another process (sessions):

jar = mimicry.new_jar(rules=profiles.chrome_macos())
tickets = mimicry.new_ticket_cache()
client = mimicry.new_client(Config(profile=profiles.chrome_macos(), cookies=jar, tickets=tickets))
...
jar.write_json("cookies.json")
tickets.write_json("tickets.json")

Cookies and tickets are credentials: a path given to write_json (and write_netscape) is written with mode 0600 and replaces the old file atomically. A file object you pass is written as you opened it. Load tickets into one process at a time.

Development

From the repository root, with Go and uv:

moon run python:test python:lint   # builds the core into src/mimicry/_bin, then pytest; ruff and mypy
moon run python:proto              # after editing proto/: regenerates src/mimicry/_pb (buf, pinned)
bash bindings/python/build-wheels.sh dist   # every platform's wheel, its core cross-compiled

Without moon: CGO_ENABLED=0 go build -o bindings/python/src/mimicry/_bin/ ./cmd/mimicry-core (PowerShell: $env:CGO_ENABLED=0 first; with a directory for -o, Go names the binary, mimicry-core.exe on Windows), then uv run pytest in bindings/python. MIMICRY_CORE (an absolute path) runs another core build. The tests replay the wire protocol's vectors (proto/testdata/wire), check the generated code against the schema, and run the SDK against a local TLS and WebSocket server; internal/harness/e2e/python_test.go checks that requests through the SDK are the Go client's on the wire (MIMICRY_PYTHON=bindings/python/.venv/bin/python go test -run TestPythonSDK ./e2e in internal/harness; a relative path there is the repository root's).

Metadata

Release files for mimicry-http 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for mimicry-http 0.7.0
File Actions
mimicry_http-0.7.0-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details for mimicry_http-0.7.0-py3-none-win_arm64.whl
mimicry_http-0.7.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for mimicry_http-0.7.0-py3-none-win_amd64.whl
mimicry_http-0.7.0-py3-none-musllinux_1_1_x86_64.whl Python 3 none Linux musl 1.1+ x86-64 Details for mimicry_http-0.7.0-py3-none-musllinux_1_1_x86_64.whl
mimicry_http-0.7.0-py3-none-musllinux_1_1_aarch64.whl Python 3 none Linux musl 1.1+ ARM64 Details for mimicry_http-0.7.0-py3-none-musllinux_1_1_aarch64.whl
mimicry_http-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for mimicry_http-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
mimicry_http-0.7.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for mimicry_http-0.7.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
mimicry_http-0.7.0-py3-none-macosx_13_0_x86_64.whl Python 3 none macOS 13.0+ x86-64 Details for mimicry_http-0.7.0-py3-none-macosx_13_0_x86_64.whl
mimicry_http-0.7.0-py3-none-macosx_13_0_arm64.whl Python 3 none macOS 13.0+ ARM64 Details for mimicry_http-0.7.0-py3-none-macosx_13_0_arm64.whl

Total release size: 46.4 MB

Release files / mimicry_http-0.7.0-py3-none-win_arm64.whl

Download URL mimicry_http-0.7.0-py3-none-win_arm64.whl
Size 5.5 MB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
031cacd2cda7a8e83f49fe293c5e50d6b1887b2320c0b4cb78da61713e45819f
BLAKE2b-256 checksum
How to use checksums
3d56b9258460953c79fcb8841fd96bb38ff40be5798a0bede3ddb84c235d8644
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / mimicry_http-0.7.0-py3-none-win_amd64.whl

Download URL mimicry_http-0.7.0-py3-none-win_amd64.whl
Size 6.1 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
11fb01580b2a44cf7522b8a424fb12bb1f10ec9f4f34f0763b9b3476b6af08ef
BLAKE2b-256 checksum
How to use checksums
2056d8f14c5a58dcdbea8756b2697e97ac769894f145469d40b032ad8720052c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / mimicry_http-0.7.0-py3-none-musllinux_1_1_x86_64.whl

Download URL mimicry_http-0.7.0-py3-none-musllinux_1_1_x86_64.whl
Size 6.0 MB
Tags Linux musl 1.1+ x86-64 Python 3
SHA-256 checksum
How to use checksums
3e92d7366c4b5dfa8b061ab1fe2b738a77970d68437efd01d099ccf701679296
BLAKE2b-256 checksum
How to use checksums
e0e93dfcde80db59080a6d88bab990ae2633272f2e64aadb78ce833bc3b28b13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / mimicry_http-0.7.0-py3-none-musllinux_1_1_aarch64.whl

Download URL mimicry_http-0.7.0-py3-none-musllinux_1_1_aarch64.whl
Size 5.4 MB
Tags Linux musl 1.1+ ARM64 Python 3
SHA-256 checksum
How to use checksums
b46f4add86f16a20e5581303d040a51927f981ead4030b8ca850a8298c29eef5
BLAKE2b-256 checksum
How to use checksums
96e4db9e220153fd2c14cec0b9e8b8c04d2f51778322a732ad874af9cc812619
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / mimicry_http-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mimicry_http-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 6.0 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
ad4f9881c1878a327a6c43a0c87dedcbb05fe08ca593c023f9eb69dceb43849f
BLAKE2b-256 checksum
How to use checksums
160cd00a3da11657202c1937f477358a35ff00c81d691e9cf6e3bc0c3a826d67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / mimicry_http-0.7.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL mimicry_http-0.7.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 5.4 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
f4d883d61bce094e50965665898b8e4bcf844bb2e219ea6719edf3159a387558
BLAKE2b-256 checksum
How to use checksums
a59290edcf1ddc64aa3f09350f3ad604a5ea70db1fc09509fa9f2f0e4d2d54c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / mimicry_http-0.7.0-py3-none-macosx_13_0_x86_64.whl

Download URL mimicry_http-0.7.0-py3-none-macosx_13_0_x86_64.whl
Size 6.1 MB
Tags Python 3 macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
47b340bb6848982aebf50237bfb2d3ca235c66acaf3a062adbeaef63a3378a07
BLAKE2b-256 checksum
How to use checksums
341e2834f11e28629c4f6f15756dd46a25035126f32c16276181f763e2798740
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / mimicry_http-0.7.0-py3-none-macosx_13_0_arm64.whl

Download URL mimicry_http-0.7.0-py3-none-macosx_13_0_arm64.whl
Size 5.7 MB
Tags Python 3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
ee37db925d98a11abbf56745abe09f233044cdb9dfc77a9445e97f12d580e634
BLAKE2b-256 checksum
How to use checksums
0f5083001b42b243cf5285a7e62802534b5105f6ed8b85cd3cb393d2934ae0c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for mimicry-http 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for mimicry_http-0.7.0-py3-none-win_arm64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page