Stoma
Define with OpenAPI. Autocomplete with Stoma.
English · 中文
Installation · Example · Key features · Docs · About
Installation
Requires Python 3.12 or higher.
pip install stoma
Example
Define an endpoint:
from typing import Annotated
from pydantic import BaseModel, Field
from stoma import APIRoute, APIRouter, ResponseSpec
class User(BaseModel):
id: Annotated[int | None, Field(examples=[10])] = None
"""Example: 10"""
username: Annotated[str | None, Field(examples=["theUser"])] = None
"""Example: 'theUser'"""
first_name: Annotated[str | None, Field(alias="firstName", examples=["John"])] = None
"""Example: 'John'"""
router = APIRouter(prefix="/api/v3")
@router.get("/user/{username}")
class GetUserByName(APIRoute):
"""Get user by user name."""
username: str
@property
def on_200(self) -> ResponseSpec[User]:
return ResponseSpec(
status_code=200,
media_type="application/json",
expected_type=User,
)
Call it:
from playwright.sync_api import sync_playwright
from stoma import Client
with sync_playwright() as p:
ctx = p.request.new_context(base_url="https://petstore3.swagger.io")
client = Client(context=ctx)
endpoint = GetUserByName(username="user1")
response = client.send(endpoint)
user = response.expect(endpoint.on_200)
assert user.username == "user1"
Key features
- The code is the protocol: Stoma holds everything needed to call an endpoint, so you no longer have to switch between your IDE and the API documentation.
- Autocomplete: thanks to Pydantic and generics, the IDE autocompletes both request parameters and response types.
- OpenAPI CLI: a CLI command generates the whole set of endpoint code from an OpenAPI spec.
Docs
- Quickstart — installation and a walkthrough against a real API.
- Defining an endpoint — an endpoint in Stoma is made of a route, its parameters, and its response specs.
- Calling an endpoint and asserting the response — use
Clientto call an endpoint and assert on its response. - Generating endpoints — Stoma provides a CLI command that generates endpoints from an OpenAPI spec.
See also the demo repository stoma-demo, which shows how Stoma is used in a real project.
About
About Stoma — where the project comes from, its inspiration, and its dependencies.
Metadata
Release files for stoma 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stoma-0.4.0.tar.gz | 3.7 MB | Without provenance | Details for stoma-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stoma-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for stoma-0.4.0-py3-none-any.whl |
Total release size: 3.7 MB
Release files / stoma-0.4.0.tar.gz
| Download URL | stoma-0.4.0.tar.gz |
|---|---|
| Size | 3.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
109fc22e07affcc04234e9d2966636314a4e865b8ad827ccb866e0dd10edef4c
|
|
BLAKE2b-256 checksum How to use checksums |
0a04230f879d528b2637963da94ac94011242b3da2702649dcdeecd52af5ec0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / stoma-0.4.0-py3-none-any.whl
| Download URL | stoma-0.4.0-py3-none-any.whl |
|---|---|
| Size | 80.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8250cded8096197e45319ee2c57bfc9b9fa3427cd663e159c8cf4cd9dced07da
|
|
BLAKE2b-256 checksum How to use checksums |
4a3deae4abd9388cdaa45102ba73e69cd89c5e0edf4e6fd9d09138542863cc85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for stoma 0.4.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.