Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

mimicry for Python

HTTP requests the way Chrome, Firefox and Safari 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).

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)
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.6.0rc1

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.6.0rc1
File Actions
mimicry_http-0.6.0rc1-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details for mimicry_http-0.6.0rc1-py3-none-win_arm64.whl
mimicry_http-0.6.0rc1-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for mimicry_http-0.6.0rc1-py3-none-win_amd64.whl
mimicry_http-0.6.0rc1-py3-none-musllinux_1_1_x86_64.whl Python 3 none Linux musl 1.1+ x86-64 Details for mimicry_http-0.6.0rc1-py3-none-musllinux_1_1_x86_64.whl
mimicry_http-0.6.0rc1-py3-none-musllinux_1_1_aarch64.whl Python 3 none Linux musl 1.1+ ARM64 Details for mimicry_http-0.6.0rc1-py3-none-musllinux_1_1_aarch64.whl
mimicry_http-0.6.0rc1-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.6.0rc1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
mimicry_http-0.6.0rc1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for mimicry_http-0.6.0rc1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
mimicry_http-0.6.0rc1-py3-none-macosx_13_0_x86_64.whl Python 3 none macOS 13.0+ x86-64 Details for mimicry_http-0.6.0rc1-py3-none-macosx_13_0_x86_64.whl
mimicry_http-0.6.0rc1-py3-none-macosx_13_0_arm64.whl Python 3 none macOS 13.0+ ARM64 Details for mimicry_http-0.6.0rc1-py3-none-macosx_13_0_arm64.whl

Total release size: 45.8 MB

Release files / mimicry_http-0.6.0rc1-py3-none-win_arm64.whl

Download URL mimicry_http-0.6.0rc1-py3-none-win_arm64.whl
Size 5.4 MB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
b25812d0eead8a50658a5f8124c07da7c3ced23bf2fc04477acc1737649933d8
BLAKE2b-256 checksum
How to use checksums
6b06d881d5f35ea3a8f3c7fab81ad847477386967465c8a4d34e354e2a3cfbcb
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 18, 2026.

Transparency log

Release files / mimicry_http-0.6.0rc1-py3-none-win_amd64.whl

Download URL mimicry_http-0.6.0rc1-py3-none-win_amd64.whl
Size 6.1 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
9409f0c7988b872c3b35de00a2cea34f269b9282ce706f834c59ee58def8c6ae
BLAKE2b-256 checksum
How to use checksums
c0704601832920b5953ab35f9d07f6e41c4c1634e2697d57188c48d764048a1c
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 18, 2026.

Transparency log

Release files / mimicry_http-0.6.0rc1-py3-none-musllinux_1_1_x86_64.whl

Download URL mimicry_http-0.6.0rc1-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
cd08bba09965691e562f213d06c0b740a7f752fee170fe3836d3a67e9aff698a
BLAKE2b-256 checksum
How to use checksums
90fbce0122caf585e9fb517a1918cc5fc3329cb5bcaefee1c068408b26d4fa8b
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 18, 2026.

Transparency log

Release files / mimicry_http-0.6.0rc1-py3-none-musllinux_1_1_aarch64.whl

Download URL mimicry_http-0.6.0rc1-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
6c29383529e3c32426ff8d5392e2f16962105684d4f1e335a4cdb770d8f6950a
BLAKE2b-256 checksum
How to use checksums
7c01d21083133532067417e735562d8697598bbdf8034d90b238be8fdb0d1388
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 18, 2026.

Transparency log

Release files / mimicry_http-0.6.0rc1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mimicry_http-0.6.0rc1-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
81e3eb2853aa06af921dcf66c75c51ad7837e646f1d429d9d3983a6c90c719f5
BLAKE2b-256 checksum
How to use checksums
9b9e2258d55bdaf38e328aa3779f421d1ad6b2a1a8cfd6d0043a501229308922
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 18, 2026.

Transparency log

Release files / mimicry_http-0.6.0rc1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL mimicry_http-0.6.0rc1-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
771210acb73aa2cfb1ef63192ac9d14c99a13419b2618323907d7e318560ef80
BLAKE2b-256 checksum
How to use checksums
de041f9bbbec3977765ea35807085be180cc8a023f39a0b4fd7256644b3f1667
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 18, 2026.

Transparency log

Release files / mimicry_http-0.6.0rc1-py3-none-macosx_13_0_x86_64.whl

Download URL mimicry_http-0.6.0rc1-py3-none-macosx_13_0_x86_64.whl
Size 6.0 MB
Tags Python 3 macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
4fe14ed4f412dbba39229244a259e7708b299cdfa810041afcaa0d1d59a7f2ee
BLAKE2b-256 checksum
How to use checksums
9833d70be09c48ed1d152f6bb9807e97c392ebda2ee68dd01500ece5b6dd46fd
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 18, 2026.

Transparency log

Release files / mimicry_http-0.6.0rc1-py3-none-macosx_13_0_arm64.whl

Download URL mimicry_http-0.6.0rc1-py3-none-macosx_13_0_arm64.whl
Size 5.6 MB
Tags Python 3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
f468aabb86f02e4845027be7ec5fca08786d3a632079f5a695b941f1f9ef289d
BLAKE2b-256 checksum
How to use checksums
e3493538267fe22860e04950a43b276c3605c295a30be5db14651f193664b854
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 18, 2026.

Transparency log

Security for mimicry-http 0.6.0rc1

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.6.0rc1-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 18, 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