Skip to main content

No project description provided

Project description

amasto

Fully async, type-safe Python client for the Mastodon API.

[!WARNING] This project contains code generated by LLMs (Large Language Models). A significant portion of the codebase has not been fully reviewed or tested. Use at your own risk.

Features

  • Async-first — All I/O uses async/await via httpx
  • Type-safe — Typed endpoint descriptors and Pydantic response models; ships with py.typed
  • Version-aware — Automatic server version detection via NodeInfo; models mark field availability with since() / Unsupported
  • Minimal surface area — Small, deliberate public API

Requirements

  • Python ≥ 3.14

Installation

pip install amasto

Or with uv:

uv add amasto

Quick start

from amasto import Amasto

async def main() -> None:
    client = Amasto("https://mastodon.social", "YOUR_ACCESS_TOKEN")

    # Post a status
    status = await client.api.v1.statuses.post(body={"status": "Hello from amasto!"})

    # Read a single status by ID
    status = await client.api.v1.statuses["123456"].get()

    # List accounts the user is following
    accounts = await client.api.v1.accounts["123456"].following.get()

Client

Amasto is the main entry point. It wraps an httpx.AsyncClient and automatically discovers the server's Mastodon version via the NodeInfo protocol on first use.

from semver import Version

client = Amasto(
    "https://mastodon.social",   # base URL
    "YOUR_ACCESS_TOKEN",         # API key (Bearer token)
    mastodon_version=Version(4, 3, 0),  # optional: skip auto-detection
)

Resources

API access uses a resource-based pattern where every endpoint is reachable as a chain of attribute accesses on the client:

client.api.v1.<resource>.<method>(params=..., body=...)
client.api.v1.<resource>["id"].<sub_resource>.<method>(...)

Each leaf node is an HttpMethod instance that is:

  • Async-callableawait method(params=..., body=...) executes the HTTP request and returns a validated response.
  • Introspectable.method, .path, and .requires expose the HTTP verb, URL path, and minimum server version.
  • Test-friendly.parse(data) validates data against the response type without making HTTP calls.

API v1 (client.api.v1)

Resource Access pattern
accounts .get, .post, .verify_credentials.get, ["id"].get, ["id"].follow.post, …
announcements .get, ["id"].dismiss.post, ["id"].reactions["name"].put
apps .post, .verify_credentials.get
blocks .get
bookmarks .get
conversations .get, ["id"].delete, ["id"].read.post
custom_emojis .get
directory .get
domain_blocks .get, .post, .delete
emails .confirmations.post
endorsements .get
favourites .get
featured_tags .get, .post, .suggestions.get, ["id"].delete
follow_requests .get, ["id"].authorize.post, ["id"].reject.post
followed_tags .get
instance .get, .peers.get, .activity.get, .rules.get, .domain_blocks.get, …
lists .get, .post, ["id"].get, ["id"].put, ["id"].delete, ["id"].accounts.get
markers .get, .post
media ["id"].get, ["id"].put, ["id"].delete
mutes .get
notifications .get, .clear.post, .unread_count.get, .requests.*, ["id"].get, ["id"].dismiss.post
polls ["id"].get, ["id"].votes.post
preferences .get
profile .avatar.delete, .header.delete
push .subscription.get, .subscription.post, .subscription.put, .subscription.delete
reports .post
scheduled_statuses .get, ["id"].get, ["id"].put, ["id"].delete
search .get
statuses .get, .post, ["id"].get, ["id"].put, ["id"].delete, ["id"].context.get, ["id"].favourite.post, …
suggestions .get, ["id"].delete
tags ["key"].get, ["key"].follow.post, ["key"].unfollow.post
timelines .public.get, .home.get, .link.get, .direct.get, .tag["hashtag"].get, .list["id"].get
trends .tags.get, .statuses.get, .links.get

API v2 (client.api.v2)

Resource Access pattern
filters .get, .post, ["id"].get/put/delete, ["id"].keywords.get/post, .keywords["id"].get/put/delete
instance .get
media .post
notifications .get, .unread_count.get, .policy.get/patch, ["group_key"].dismiss.post, ["group_key"].accounts.get
search .get
suggestions .get

OEmbed (client.api.oembed)

Access Description
.get Fetch oEmbed data for a status URL

OAuth (client.oauth)

Resource Access
authorize .get — Authorization URL
token .post — Obtain a token
revoke .post — Revoke a token
userinfo .get — Authenticated user info

Health (client.health)

Access Description
.get Server health check

Models

Response models live under amasto.models and are re-exported from amasto.models.v1 and amasto.models.v2. All models are frozen Pydantic BaseModel subclasses.

V1 models

Account, AccountRole, AccountSource, AccountWarning, Announcement, AnnouncementAccount, AnnouncementStatus, Appeal, Application, AsyncRefresh, Context, Conversation, CredentialAccount, CredentialApplication, CustomEmoji, DomainBlock, EncryptedMessage, Error, ExtendedDescription, FamiliarFollowers, FeaturedTag, Field, IdentityProof, InstanceStats, InstanceUrls, List, Marker, MediaAttachment, MutedAccount, Notification, NotificationRequest, Poll, PollOption, Preferences, PreviewCard, PreviewCardAuthor, PrivacyPolicy, Quote, QuoteApproval, Reaction, Relationship, RelationshipSeveranceEvent, Report, Role, Rule, ScheduledStatus, ScheduledStatusParams, ScheduledStatusParamsPoll, Search, ShallowQuote, Status, StatusEdit, StatusEditPoll, StatusEditPollOption, StatusMention, StatusSource, StatusTag, Suggestion, Tag, TagHistory, TermsOfService, Token, Translation, TranslationAttachment, TranslationPoll, TranslationPollOption, TrendsLink, WebPushAlerts, WebPushSubscription

V2 models

Filter, FilterKeyword, FilterResult, FilterStatus, Instance, InstanceConfiguration, InstanceConfigurationAccounts, InstanceConfigurationMediaAttachments, InstanceConfigurationPolls, InstanceConfigurationStatuses, InstanceConfigurationTimelinesAccess, InstanceConfigurationTimelinesFeedAccess, InstanceConfigurationTranslation, InstanceConfigurationUrls, InstanceConfigurationVapid, InstanceContact, InstanceIcon, InstanceRegistrations, InstanceThumbnail, InstanceThumbnailVersions, InstanceUsage, InstanceUsageUsers, NotificationPolicy, NotificationPolicySummary

Version awareness

Model fields annotated with since("x.y.z") resolve to Unsupported when the connected server is older than the specified version, so your code can safely handle missing data:

from amasto.models import Status
from amasto._version import Unsupported

if not isinstance(status.poll, Unsupported):
    print(status.poll)

Endpoints can also declare requires="x.y.z" to indicate the minimum server version.

Dependencies

Package Purpose
httpx ≥ 0.28.1 Async HTTP client
pydantic ≥ 2.12.5 Response validation and models
semver ≥ 3.0.4 Server version parsing

License

See LICENSE for details.

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

amasto-0.2.0.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

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

amasto-0.2.0-py3-none-any.whl (70.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: amasto-0.2.0.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for amasto-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f794fdd446d597436cecd36b81f4c18ae48107e4fb30cb689e580f7ec2344e75
MD5 0f0e50d00ca5fb9edd3a2c3e3ed8a414
BLAKE2b-256 6971cfca711ca3b650ed93f963d930e1e2e0a8f199569e4690ccdd19bd80f5d8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: amasto-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 70.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for amasto-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e747a5e30f1a4d99241ccb86ebea73c67cacd7a4afee9198ba61352fc055411b
MD5 ee3b29ed61d5349e13f0e0353b76ec2b
BLAKE2b-256 ff526d0b4dc58b69796c0127af8338880f5ca9ca924203f778379a288280e54d

See more details on using hashes here.

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