Skip to main content

Mastodon Mock

PyPI version CI Python versions License: MIT

mastodon_mock is a stateful, local Mastodon REST API for tests and development. It runs a real FastAPI server backed by in-memory or file-backed SQLite, so client code can post statuses, follow accounts, build timelines, manage lists and filters, file reports, and exercise OAuth/admin flows without touching a live instance.

Use it when you want the confidence of real HTTP and persisted state, without flaky network tests, rate limits, public test posts, or hand-written response mocks.

Highlights:

  • Real Mastodon-shaped HTTP API, tested against Mastodon.py.
  • Fast disposable SQLite state, with deterministic seed data and reset support.
  • Pytest fixtures, a context manager, and decorator sugar for zero-boilerplate tests.
  • Bulk sample-data generation for demos, UI work, and performance checks.
  • Bundled web client and admin UI at /_ui/ when the package includes the built frontend.
  • Admin/moderation endpoints for account actions, reports, domain blocks, email blocks, and IP blocks.

Installation

pipx install mastodon_mock

Or with pip:

pip install mastodon_mock

Usage

Run the mock server:

mastodon_mock serve --in-memory

Point a client at it:

from mastodon import Mastodon

client = Mastodon(access_token="mock_token", api_base_url="http://127.0.0.1:3000")
client.status_post("hello from a mock!")

Open http://127.0.0.1:3000/_ui/ for the bundled browser UI when it is available. The UI covers timelines, compose/reply, boost/favourite/bookmark, quote posts, threads, profiles, search, lists, an About this server page (instance rules, terms of service, custom emojis), an announcements banner (dismiss + emoji reactions), and an admin panel (accounts, reports, domains, announcements, trends).

For a quick, good-looking demo with a small community already populated — multiple accounts, follows, a quote post, announcements, rules, and terms of service — run:

mastodon_mock serve --in-memory --demo

For a populated local instance, generate a throwaway cohort into a SQLite file and point your config's [database].path at it:

mastodon_mock gen-data --preset small --database ./mastodon_mock.sqlite --yes

HTTPS (required for most Mastodon clients, e.g. Whalebird, Fedistar)

Desktop/mobile Mastodon clients connect to the entered domain over HTTPS regardless of any scheme you type, so pointing one at a plain-HTTP serve instance fails with Invalid HTTP request received in the server log (the client's TLS handshake hitting an HTTP parser).

A plain openssl self-signed cert is often not enough — Electron-based clients (Whalebird, Fedistar) commonly refuse to connect at all rather than warn-and-allow like a browser does. Use mkcert instead: it installs a local CA into your OS trust store and issues certs signed by it, so clients trust the connection outright.

make dev-cert      # generates .dev_certs/ via mkcert if installed, else falls back to openssl
make serve-https    # dev-cert + serve --in-memory --demo --port 3443 over HTTPS

Or run the steps by hand:

mkcert -install   # one-time: adds a local CA to the OS/browser trust stores
mkcert -key-file .dev_certs/localhost-key.pem -cert-file .dev_certs/localhost-cert.pem \
  localhost 127.0.0.1 ::1

mastodon_mock serve --in-memory --demo --port 3443 \
  --ssl-keyfile .dev_certs/localhost-key.pem --ssl-certfile .dev_certs/localhost-cert.pem

Point the client at https://127.0.0.1:3443 (or localhost). Without mkcert installed, gen-dev-cert.sh falls back to an openssl self-signed cert, but expect Electron clients to refuse it outright rather than just warn.

See HTTPS and Real Mastodon Clients for the full walkthrough (mkcert setup, troubleshooting, and how serve derives a reachable domain for avatar/header/status URLs).

Why I think this works

  • 100s of unit tests
    • Ordinary pytests
    • Integration tests via live server
    • Integration tests via Angular client
  • Unit tests using mastodon-py
  • Hand tested with half a dozen clients
  • Bundled with an Angular client written specifically to test the mock server
  • Schema compared with the reverse engineered OpenAPI schema
  • Tested against five of my own Mastodon projects
  • Test data generation uses mastodon-mock

Tested on...

  • Tuba - Works, but had to use port 443 and edit hosts file so cert matched domain (mock.local in my case)
  • Whalebird- Works!
  • Fedistar - couldn't get it to trust local certificate
  • Dowstodon - Works!
  • Various web - They need to make a serverside request to my machine. Can't do it, without putting a mock server on public web.
  • toot - can't test on Windows
  • Sengi - couldn't get this to work? But not sure the Sengi app is finished either (as of 6/2026)?

Documentation

See the documentation for configuration, fixtures, endpoint coverage, data generation, and admin UI/API details.

Contributing

See CONTRIBUTING.md.

License

MIT. See LICENSE.

Changelog

See CHANGELOG.md.

Metadata

Release files for mastodon-mock 0.7.0

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

Source distribution (sdist)

Source distribution for mastodon-mock 0.7.0
File Size Uploaded Provenance Actions
mastodon_mock-0.7.0.tar.gz 350.4 kB With provenance Details for mastodon_mock-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mastodon-mock 0.7.0
File Interpreter ABI Platform Actions
mastodon_mock-0.7.0-py3-none-any.whl Python 3 none any Details for mastodon_mock-0.7.0-py3-none-any.whl

Total release size: 720.3 kB

Release files / mastodon_mock-0.7.0.tar.gz

Download URL mastodon_mock-0.7.0.tar.gz
Size 350.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c4bf913d6bd6449b091fac4d40516d6fd5054488b5878baf13575909a00d3c62
BLAKE2b-256 checksum
How to use checksums
d1cd92b30aeccd962a74b47a34455a98310af267e555075e3aa360ba60ab5174
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 11, 2026.

Transparency log

Release files / mastodon_mock-0.7.0-py3-none-any.whl

Download URL mastodon_mock-0.7.0-py3-none-any.whl
Size 369.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57858264d7f10d828c1cff375f157a1444a92bc52f6e9fb3948e1e249293e353
BLAKE2b-256 checksum
How to use checksums
5cda630bf720303f6ceac5ae86326f9cfff0bfad2dec60cc619308ce35623abd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 11, 2026.

Transparency log

Security for mastodon-mock 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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mastodon_mock-0.7.0.tar.gz

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 11, 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