mocket
Socket Mock Framework - for all kinds of socket animals, web-clients included - with gevent/asyncio/SSL support
What it is and what it does
Mocket monkey-patches Python's socket and ssl modules to intercept network calls during testing, allowing you to define mock responses without touching the real network. It serves two roles: as a low-level framework for building custom protocol mocks (e.g., for new databases or protocols) and as a ready-to-use HTTP/HTTPS mock. The package includes a basic Redis mock and supports gevent, asyncio, and SSL out of the box.
You register mock entries with expected URLs, methods, and response bodies, then use a decorator or context manager to activate mocking for your test. Mocket also offers strict mode to fail tests that attempt real network access, and can verify that all registered mock entries were actually used. It depends on decorator, h11, puremagic, typing-extensions, and urllib3 at runtime.
Use it for:
- Test HTTP/HTTPS clients without hitting real endpoints or rate limits.
- Mock HTTPS calls with SSL support in unit tests for web service integrations.
- Build custom protocol mocks for testing database clients or proprietary socket-based services.
- Enforce network isolation in CI/CD by using strict mode to fail tests that leak real socket calls.
- Test error paths by mocking socket exceptions and connection failures.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Mocket is a socket mocking framework that intercepts and replaces socket and SSL module calls, enabling you to test socket-based clients without real network traffic.
Yes. Mocket is mature (active maintenance, 312 GitHub stars, no known vulnerabilities), has low install friction, and solves a real testing problem—isolating socket-based code from the network. Use it if you need to mock HTTP clients, test asyncio/gevent code, or build custom protocol mocks. The permissive BSD-3-Clause license poses no restriction.
Install
mocket on PyPI
pip
pip install mocketuv
uv add mocketpoetry
poetry add mocketInstalling mocket
Before you install
Low friction: pure Python wheel with five lightweight runtime dependencies (decorator, h11, puremagic, typing-extensions, urllib3). Actively maintained with a recent release; last commit 2026-07-13. Supports modern Python versions (3.8–3.14) and PyPy.
License in practice
BSD-3-Clause (permissive): you can use, modify, and distribute mocket in proprietary projects without restriction, provided you include the license notice.
Quickstart
pip install mocket
from mocket import mocketize
from mocket.mocks.mockhttp import Entry
@mocketize
def test_api():
Entry.single_register(
Entry.GET,
'https://api.example.com/data',
body='{"key": "value"}',
headers={'content-type': 'application/json'}
)
Verify before relying
- Whether the Redis mock implementation is feature-complete enough for production test scenarios.
- Performance characteristics when mocking high-volume socket interactions.
- Compatibility with less common async frameworks beyond gevent and asyncio.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 5 — decorator, h11, puremagic, typing-extensions, urllib3 |
| Maintenance | actively maintained — 32 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 261,074/month — #8,388 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: mocket-3.14.3-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
httmockIntercepts and mocks HTTP requests made by the…
permissive · top 5,000 on PyPI
urllib3-mockMocks urllib3 HTTP requests in tests by…
permissive · top 15,000 on PyPI
aiointerceptIntercepts aiohttp client requests by routing…
permissive · top 15,000 on PyPI
pookpook intercepts and mocks HTTP traffic for…
permissive · top 15,000 on PyPI
responsesMocks HTTP requests made by the requests…
permissive · top 1,000 on PyPI
pytest-responsesAutomatically mocks HTTP requests across your…
permissive · top 15,000 on PyPI
wiremockPython client library for interacting with…
permissive · top 15,000 on PyPI
pytest-httpbinProvides a pytest fixture that runs a local…
permissive · top 15,000 on PyPI
pytest-localserverProvides pytest fixtures that spin up local…
permissive · top 15,000 on PyPI
moto-extMocks AWS services for testing by intercepting…
permissive · top 15,000 on PyPI