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.0rc3

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

Total release size: 45.8 MB

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

Download URL mimicry_http-0.6.0rc3-py3-none-win_arm64.whl
Size 5.4 MB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
7a1de088d539c77095a03e93a8cd9045c6e5980605f8165cdc332994e7a77025
BLAKE2b-256 checksum
How to use checksums
3ab8be7715dbc103cd1b98df5745647312b1dcc9bd24099d28cef01fd6bb4e76
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.0rc3-py3-none-win_amd64.whl

Download URL mimicry_http-0.6.0rc3-py3-none-win_amd64.whl
Size 6.1 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
fff38fabb69bb8e20d0eef282d346a21bafd1222f7ff2252b401565128f7d4e5
BLAKE2b-256 checksum
How to use checksums
3cc69a9ca47d024981509b84a9e817755884dc9717c5fd88cae133ef3571e7ed
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.0rc3-py3-none-musllinux_1_1_x86_64.whl

Download URL mimicry_http-0.6.0rc3-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
fb39b734b68cb817a70902f9bab5970c986c66d0712c18c361aa28707d71734f
BLAKE2b-256 checksum
How to use checksums
94d04811ba391e2c969408bb7a050e48ab874fd565dadc3365094726399f9434
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.0rc3-py3-none-musllinux_1_1_aarch64.whl

Download URL mimicry_http-0.6.0rc3-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
e8a772c75418834d1df2964b9843fdd08006cac45dfdd6d1527b1ff7727e4bd6
BLAKE2b-256 checksum
How to use checksums
7f5909d05fa0f0dfa04a827f922ebb168363942cb56adc3c8480f26eb3c4a708
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.0rc3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mimicry_http-0.6.0rc3-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
63420e498a78f69aae387e89a14271d69b77d4f2b81f82ebb681461586a20394
BLAKE2b-256 checksum
How to use checksums
c0655bd6ceb4d85830d2b18182a1838a4f1af2b86d9f2d626df7e57254e7f7c2
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.0rc3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL mimicry_http-0.6.0rc3-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
5071a8d03c0b6da43685ff1b296bf9f671c7e1b1573c0f0fc644cb21c9d8e991
BLAKE2b-256 checksum
How to use checksums
7aa51d8f0945b7c656224b424994cfea789332947b10f884c81c73bdaab82a7a
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.0rc3-py3-none-macosx_13_0_x86_64.whl

Download URL mimicry_http-0.6.0rc3-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
cf541b1375c2c8aea839f4f84fc42818620b35572067b4fee492ea867ce1500b
BLAKE2b-256 checksum
How to use checksums
daea348da63892b475773712800e3ac3ce10d2113ac53c02758bdd589da25f41
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.0rc3-py3-none-macosx_13_0_arm64.whl

Download URL mimicry_http-0.6.0rc3-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
dbe303da3e1b4a009df8bea5d4fd11f6650a21d95586084697ad8709d601c96c
BLAKE2b-256 checksum
How to use checksums
ff3cd71e022282f955a67b5d841b99a6f73e9a336776d5c14a423a76b803a72e
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.0rc3

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.0rc3-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