Skip to main content

Stateful in-memory/SQLite mock of the Mastodon REST API for testing Mastodon clients

Project description

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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mastodon_mock-0.2.0.tar.gz (232.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mastodon_mock-0.2.0-py3-none-any.whl (275.2 kB view details)

Uploaded Python 3

File details

Details for the file mastodon_mock-0.2.0.tar.gz.

File metadata

  • Download URL: mastodon_mock-0.2.0.tar.gz
  • Upload date:
  • Size: 232.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for mastodon_mock-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8d3a51362235a3794ed7d6a29257581373db67de8c99d58ec24b56b47dc5305c
MD5 83eb61a81f48c968f86eb62c6f0ac660
BLAKE2b-256 782b7b0a592306eea25bc3ff796b261c4a8ebcc8267c5fbbffc5ded1008080b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for mastodon_mock-0.2.0.tar.gz:

Publisher: release.yml on matthewdeanmartin/mastodon_mock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mastodon_mock-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mastodon_mock-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 275.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for mastodon_mock-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7035dcf569d864c1f7b826eca1c38095b1c12be93585672d836d043d101d7d14
MD5 e11a33cf3e5cde3bdfcaeb31995d6e01
BLAKE2b-256 0428b2c1345499740bf96e409165e7502438ec8aef1af495d65ad3801c6f16f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mastodon_mock-0.2.0-py3-none-any.whl:

Publisher: release.yml on matthewdeanmartin/mastodon_mock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page