skillfed

mocket

Socket Mock Framework - for all kinds of socket animals, web-clients included - with gevent/asyncio/SSL support

mocket v3.14.3 261.1K downloads/30d#8,388 on PyPI312
Permissive license BSD-3-Clause Active released

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 mocket

uv

uv add mocket

poetry

poetry add mocket

Installing 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

Development Status :: 6 - MatureIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software DevelopmentTopic :: Software Development :: Testing

Tags

socket mocking frameworkmock http requests testingintercept socket callstest without networkasyncio socket mockssl mock testinggevent socket mocking
testing-frameworksocket-mockingasyncio-support

More Software Development packages