Skip to main content

qubrics-mailbox

PyPI version Python versions PyPI downloads Licence

Generated Python client for the Qubrics Mailbox API.

Version 3.0.0 excludes calendar and calendar-event clients and models. Mail, folders, drafts and mailbox event streams remain available.

Documentation

Requirements

  • Python 3.10 or newer.
  • A mailbox-scoped smx_mbx_* key or scoped smx_agent_* token.

For OAuth, use a REST access token with the scopes and mailbox access required by the operation. See OAuth for REST APIs.

Installation

These commands target the Qubrics release of qubrics-mailbox. Until it is published, install sendmux-mailbox with its existing import names.

pip install qubrics-mailbox

OAuth access tokens

Pass either api_key or access_token. access_token accepts a bare token string or a synchronous callable; the callable is evaluated for each authenticated request. Your application owns token storage, expiry checks and refresh coordination.

import os

from qubrics.mailbox import create_mailbox_client

client = create_mailbox_client(
    access_token=lambda: os.environ["QUBRICS_ACCESS_TOKEN"]
)

Usage

import os

from qubrics.mailbox import MailboxAPIApi, create_mailbox_client, iter_mailbox_events

client = create_mailbox_client(api_key=os.environ["QUBRICS_MAILBOX_API_KEY"])
api = MailboxAPIApi(client)

messages = api.mailbox_list_messages(limit=25)

for message in messages.data:
    print(message.id, message.subject)

The package exports every generated Mailbox model and API class plus:

  • create_mailbox_client
  • configure_mailbox
  • QubricsMailboxApiClient
  • iter_mailbox_events
  • file helpers: upload_mailbox_attachment_from_file, create_mailbox_attachment_upload_from_file, upload_mailbox_attachment_via_presigned_file, and send_mailbox_message_with_files

Connection checks

Check the current credential before choosing a mailbox:

with create_mailbox_client(api_key=os.environ["QUBRICS_MAILBOX_API_KEY"]) as client:
    connection = MailboxAPIApi(client).mailbox_get_connection()
    print(connection.data.label)

The result includes team and credential details, permissions and authorised mailboxes.

Attachments

Message and event attachment metadata includes download_url, a short-lived presigned URL for that single attachment. Prefer download_mailbox_attachment() or read_mailbox_text_attachment() when you already have an authenticated client. Plain HTTP clients can fetch download_url promptly with no Authorization header; if it expires, call mailbox_get_message() or list/search messages again to receive fresh metadata.

Mailbox direct uploads, presigned uploads, and file helpers share the mailbox attachment cap, currently 7,500,000 bytes per attachment. Presigned uploads also pin the exact declared byte length and content type.

import os
import urllib.request

from qubrics.mailbox import MailboxAPIApi, create_mailbox_client, read_mailbox_text_attachment

client = create_mailbox_client(api_key=os.environ["QUBRICS_MAILBOX_API_KEY"])
api = MailboxAPIApi(client)

message = api.mailbox_get_message("msg_123")
attachment = message.data.attachments[0]
content = urllib.request.urlopen(attachment.download_url, timeout=30).read()
text = read_mailbox_text_attachment(
    client,
    message_id="msg_123",
    attachment_id=attachment.id,
)

upload = api.mailbox_upload_attachment(
    body=b"hello\n",
    filename="hello.txt",
    _headers={"Content-Type": "text/plain"},
)

api.mailbox_send_message(
    send_mailbox_message_body={
        "to": [{"email": "recipient@example.com", "name": None}],
        "subject": "Attachment",
        "text_body": "See attached.",
        "attachments": [{
            "blob_id": upload.data.blob_id,
            "filename": "hello.txt",
            "content_type": "text/plain",
        }],
    },
)

For local files, use helper functions so file bytes stay out of model context:

import os

from qubrics.mailbox import create_mailbox_client, send_mailbox_message_with_files

client = create_mailbox_client(api_key=os.environ["QUBRICS_MAILBOX_API_KEY"])

send_mailbox_message_with_files(
    client,
    files=["./report.pdf"],
    idempotency_key="report-123",
    body={
        "to": [{"email": "recipient@example.com", "name": None}],
        "subject": "Report",
        "text_body": "Attached.",
    },
)

Use upload_mailbox_attachment_via_presigned_file(...) when you want the upload step to use the short-lived signed URL and no API key on the file PUT. Inline base64 attachments remain available for tiny generated sends through the generated attachments[].content body shape.

Events

Use iter_mailbox_events for typed server-sent mailbox events.

for event in iter_mailbox_events(
    client,
    close_after=300,
    event_types="message.received",
):
    print(event.event_type, event.message_id)

Pagination

Use iter_cursor_pages from qubrics-core with list operations that return cursor pagination.

import os

from qubrics.core import iter_cursor_pages
from qubrics.mailbox import MailboxAPIApi, create_mailbox_client

client = create_mailbox_client(api_key=os.environ["QUBRICS_MAILBOX_API_KEY"])
api = MailboxAPIApi(client)

for message in iter_cursor_pages(lambda cursor: api.mailbox_list_messages(cursor=cursor, limit=50)):
    print(message.id)

Thread message model migration

If you annotate or construct thread-message list results (fixtures, mocks, or wrappers typed with the operation's result model), add the thread identity. mailbox_list_thread_messages returns MailboxThreadMessageSummaryCursorListResponse instead of MailboxMessageSummaryCursorListResponse: its meta is MailboxThreadMessagesMeta, whose thread_id is required and whose sync_state is an optional string. Code that only reads thread-message results keeps working.

  1. Update thread-message annotations and type checks to the thread-specific result model:

    from qubrics.mailbox import MailboxThreadMessageSummaryCursorListResponse
    
    # Before: isinstance(response, MailboxMessageSummaryCursorListResponse)
    def is_thread_message_list(response: object) -> bool:
        return isinstance(response, MailboxThreadMessageSummaryCursorListResponse)
    
  2. Add the thread identity to every thread-message result you construct:

    from qubrics.mailbox import MailboxThreadMessageSummaryCursorListResponse
    
    # Before: "meta": {"request_id": "req_fixture"}
    fixture = MailboxThreadMessageSummaryCursorListResponse.model_validate(
        {
            "ok": True,
            "meta": {"request_id": "req_fixture", "thread_id": "thr_1"},
            "data": [],
            "pagination": {"has_more": False},
        }
    )
    

    Ordinary mailbox_list_messages results remain MailboxMessageSummaryCursorListResponse: they have no thread identity and their meta is MailboxSyncMeta with an optional sync_state. Identity, submission, quota, and thread list responses likewise carry MailboxIdentityListMeta or MailboxQueryMeta with optional identity_state or query_state; no new field is required there.

  3. Run your tests and mypy. A constructed thread-message result without thread_id fails validation with meta.thread_id Field required.

MailboxRealtimeMessage.body is a MailboxRealtimeMessageBody. The earlier generated name, MailboxRealtimeMessageAllOfBody, remains importable from qubrics.mailbox and qubrics.mailbox.models as a deprecated alias of that class: reading it emits a DeprecationWarning. Switch imports to MailboxRealtimeMessageBody.

Update qubrics-mailbox, its lockfile, and affected annotations or fixtures together. To roll back, restore those package, lockfile, and call-site changes together.

Support

Open an issue in qubrics/qubrics-sdk with the package name, version, and request ID from any API error.

Licence

MIT. See the licence file.

Metadata

Release files for qubrics-mailbox 3.0.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 qubrics-mailbox 3.0.0
File Size Uploaded Provenance Actions
qubrics_mailbox-3.0.0.tar.gz 95.7 kB Without provenance Details for qubrics_mailbox-3.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qubrics-mailbox 3.0.0
File Interpreter ABI Platform Actions
qubrics_mailbox-3.0.0-py3-none-any.whl Python 3 none any Details for qubrics_mailbox-3.0.0-py3-none-any.whl

Total release size: 383.6 kB

Release files / qubrics_mailbox-3.0.0.tar.gz

Download URL qubrics_mailbox-3.0.0.tar.gz
Size 95.7 kB
Tags Source
SHA-256 checksum
How to use checksums
11023962d63cd7e154892efb2abd599a0c707c10087f7096b1a3d8d7a5abe980
BLAKE2b-256 checksum
How to use checksums
4715be74248278a9d64cbc639b07bfb1f49ad9cd23bd7d77eacb7f4adc935f0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / qubrics_mailbox-3.0.0-py3-none-any.whl

Download URL qubrics_mailbox-3.0.0-py3-none-any.whl
Size 287.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6dc0f21a4e5c85875d8cfb8eeb8901675aabc647572bf58088354c7d2d4f97b0
BLAKE2b-256 checksum
How to use checksums
a2577dea4ea0415adb7724b09d93610991476bc835b187f0821af9458fcc4388
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Security for qubrics-mailbox 3.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files No provenance

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