Skip to main content
The Mesa Python SDK is the ergonomic async client for Mesa. It wraps the generated mesa-rest client, resolves the default organization for you, and exposes a native virtual filesystem for repo I/O and shell execution. Python 3.10 or newer is required.

Installation

Create a client

Set MESA_PRIVATE_KEY in a trusted environment to omit private_key from the constructor.

Client options

str | None
Ed25519 private key. The SDK reads MESA_PRIVATE_KEY when no explicit private key is supplied.
str
REST API base URL. Defaults to https://api.mesa.dev/v1. http and https are accepted. Trailing slashes are stripped.
str | None
Appended to the SDK user agent. The default user agent starts with mesa-sdk-python.

Client lifecycle

Create one Mesa client for your process or application and reuse it across request handlers. If your framework has a lifespan hook and you want explicit cleanup, wrap the client in async with Mesa(...) at application lifespan, not inside each handler.

Organization resolution

The client reads its organization from the private key. Resource methods always use that organization and do not accept an org value.
Use await mesa.org.get() when you need organization metadata from the API.

Resource APIs

Response objects

The high-level SDK returns model instances generated by mesa-rest. Use attribute access, not dictionary access.

Common types

Import common dataclasses and native result types from mesa_sdk.
Upstream configuration types live in mesa_sdk.types:
On mesa.repos.update(...), UpstreamConfig.auth is tri-state: omit to preserve existing credentials, pass None to clear credentials, or pass TokenAuth / UsernamePasswordAuth to set credentials.

Error model

REST API operations raise MesaError subclasses. SDK setup errors include MissingCredentialError, InvalidApiUrlError, OrgResolutionError, and InvalidOptionsError. Filesystem and Bash operations raise built-in Python exceptions such as FileNotFoundError, FileExistsError, IsADirectoryError, NotADirectoryError, PermissionError, NotImplementedError, and OSError.

Raw generated client

mesa.raw exposes the authenticated generated mesa-rest client. Use it when the high-level SDK does not expose a generated REST operation or option yet.
Raw generated calls return a Response[T] wrapper with status_code, parsed, and headers. High-level SDK methods unwrap successful responses and raise typed errors for non-2xx responses.

Complete example