Skip to main content

mailbox-client

CI PyPI benethos-mailbox-client Python License

Beta, version 0.3.1. Usable with real accounts. A breaking change of the API or the configuration is announced in the changelog. Stored data is carried forward by migrations.

The Python client of the REST API of mailbox-service, on PyPI as benethos-mailbox-client. It reads, searches, sorts, drafts and sends mail of the accounts the service holds, as far as its token allows. The MCP server of the project, mailbox-mcp, is built on it.

It knows the service through its REST API alone, and needs nothing but httpx. The REST API follows the status above. This package's Python interface has no stability promise yet: it follows what the MCP server and the project's own checks need.

What the project is for: the repository's README.

Install

uv add benethos-mailbox-client      # or: pip install benethos-mailbox-client

Use

Make a token on your user's page in the service's UI. The client reads it from MAILBOX_SERVICE_TOKEN, and the address of the service from MAILBOX_SERVICE_URL (default http://127.0.0.1:8080). Both can be passed as arguments instead.

For async code:

from benethos_mailbox_client import MailboxClient

async with MailboxClient() as mailbox:
    me = await mailbox.me()
    for account in me.accounts:
        page = await mailbox.list_messages(account.id, folder="inbox", limit=10)
        for summary in page.items:
            print(account.email, summary["subject"])

For code without an event loop, SyncMailboxClient has the same methods (close() for aclose()) and answers the same records:

from benethos_mailbox_client import SyncMailboxClient, message_body

with SyncMailboxClient() as mailbox:
    body = message_body(
        to=[("someone@example.org", None)],
        cc=[],
        bcc=[],
        subject="Hello",
        text="Hi there",
        html=None,
        reference=None,
    )
    mailbox.send_message("acc_...", body, idempotency_key="hello-1")

request(method, path, ...) reaches any route of the API the methods do not cover and answers its JSON. The routes and their fields: docs/openapi.json.

The token travels in a header. Over http the client talks only to this machine. To another machine it needs https, or MAILBOX_SERVICE_ALLOW_HTTP=1 (allow_http=True) for a network you trust, such as between containers.

A client made without an address or a token reads the environment when it is made. A program that makes clients for a long time can read it once, with from_environment():

from benethos_mailbox_client import MailboxClient, from_environment

found = from_environment()
client = MailboxClient(found.url, found.token, allow_http=found.allow_http)

Errors

Everything the client raises is a MailboxError:

Error When
ConfigurationError no token, or an address it refuses
ServiceUnavailableError the service cannot be reached
ServiceTimeoutError the service took the request but did not answer in time
ApiError the API answered with an error: status, code, message

Inside

Each endpoint is described once, in endpoints/, one module per resource of the API: its method, path, query, body and how its answer becomes a record. That package sends nothing. MailboxClient sends those requests with httpx.AsyncClient, SyncMailboxClient with httpx.Client, and a method of either is a line or two, get_attachment, which streams, a few more. What both share stands beside them: the address and the token (environment.py), the shape of a request (calls.py), how an answer or a failure is read (answers.py) and an attachment read in chunks (attachments.py).

License

MIT, see LICENSE.

Metadata

Release files for benethos-mailbox-client 0.3.1

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

Source distribution (sdist)

Source distribution for benethos-mailbox-client 0.3.1
File Size Uploaded
benethos_mailbox_client-0.3.1.tar.gz 22.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for benethos-mailbox-client 0.3.1
File Interpreter ABI Platform
benethos_mailbox_client-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 45.5 kB

Release files / benethos_mailbox_client-0.3.1.tar.gz

Download URL benethos_mailbox_client-0.3.1.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f8073dc308b21e32e37a5c32e42aab7a5a19c29f9eb5837b2420e6621ad67604
BLAKE2b-256 checksum
How to use checksums
41a4a2b39c3e5c42b046fbc5fdd3d80227b1a8f5bd93d0400bf6c0b9f4348f63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / benethos_mailbox_client-0.3.1-py3-none-any.whl

Download URL benethos_mailbox_client-0.3.1-py3-none-any.whl
Size 23.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d5b31bca928b0555e2cf168b449d5d682f161e2f1803059db462dcaad2e78a8
BLAKE2b-256 checksum
How to use checksums
d68aece87980031854a7dc2e4646e0d852b6dfe1d5091e686fb065e2df1b27e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.4.1

2 release files

0.4.0

2 release files

This release

0.3.1 This release

2 release files

0.3.0

2 release files

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