Skip to main content

A lightweight CLI tool to generate a type-safe Python client from an OpenAPI specification.

Project description

[!WARNING] Early Development: This project is under active development. APIs may change.


openapi-burrito logo

openapi-burrito

Wrap your OpenAPI specs in type-safe Python clients

PyPI version Python License OpenAPI

Table of Contents

Quick Start

# Install
uv tool install openapi-burrito

# Generate
openapi-burrito generate openapi.json -o ./my_client
from my_client import Client

api = Client(base_url="https://api.example.com")

# Path-first API: type-checked paths and snake_case parameters
res = api.GET("/users/{user_id}", user_id=123)

if res.is_success:
    print(res.data)
else:
    print(f"Error {res.status_code}: {res.error}")

Features

  • Path-First API - Call endpoints by path literal (api.GET("/users/{user_id}")), with full IDE autocomplete for paths and parameters
  • Type-Safe - TypedDict models and @overload signatures
  • Zero Runtime - Generated code is yours, no runtime dependency on this tool
  • httpx-Based - Async support, connection pooling, all httpx features
  • Middleware System - Logging, retry, auth via composable middleware
  • Snake Case Params - Path parameters auto-converted to Python style ({userId}{user_id})

Installation

For Users

# As a CLI tool (recommended)
uv tool install openapi-burrito

# With preview server support (Swagger UI, Redoc)
uv tool install openapi-burrito[preview]

For Developers

# Clone and install all dev dependencies
git clone https://github.com/simon-lund/openapi-burrito.git
cd openapi-burrito
make install

# Run linting and type checks
make lint

# Run tests
make test

Security

This generator sanitizes identifiers and string literals to prevent code injection from malformed OpenAPI specs. However, always review untrusted specs before generating.

Parser Safety Audit

All fields output by the parser are validated/sanitized:

Field Validation Notes
Model/param names sanitize(mode="id") Converted to valid Python identifiers
Paths sanitize(mode="str") String-escaped for literals
Descriptions/docs sanitize(mode="doc") Docstring-escaped
type strings Type translator Built from validated schema types
method HTTPMethod enum Only known HTTP methods allowed
in (param location) Enum check Only path|query|header|cookie
required, read_only, write_only bool() cast Forced to boolean
default repr() Python string representation

A malicious spec could attempt injection like:

components:
  schemas:
    "User:\n    pass\nimport os; os.system('rm -rf /')  # ":
      type: object

While this generator escapes such payloads, the safest approach is to only generate clients from trusted sources.

See CVE-2020-15142 for an example of this vulnerability class in other generators.

Documentation

Guide Description
Introduction Installation and basic usage
Authentication API keys, tokens, OAuth patterns
Middleware Logging, retry, custom handling
Type System UNSET, Unknown, NotRequired, limitations
CLI Reference generate and preview commands
Contributing Development setup and guidelines

Examples

See the examples/ directory:

Star History

Star History Chart

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

openapi_burrito-0.1.1.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

openapi_burrito-0.1.1-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file openapi_burrito-0.1.1.tar.gz.

File metadata

  • Download URL: openapi_burrito-0.1.1.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openapi_burrito-0.1.1.tar.gz
Algorithm Hash digest
SHA256 637ff13634690650dc4e7c7465b03c65c3e623b7a63f9022e3e0234e9c303e13
MD5 127bc469baf880af2589c48400456742
BLAKE2b-256 0a8ef83f01ea6521b15900a58caa55ae17dcbc2b686ee02414c67a780a52c761

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_burrito-0.1.1.tar.gz:

Publisher: publish.yml on simon-lund/openapi-burrito

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openapi_burrito-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for openapi_burrito-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d8c24c27754d9b0f216be641b148961abca2f6c2de8f458d638dc8bca7b0be0f
MD5 e1a82b23b347b78cdc57db7eb8e6d66e
BLAKE2b-256 8af4b681dcea86dedd32610bd3c8a9ff36c50ca4551c64d8852228443d1f5f1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_burrito-0.1.1-py3-none-any.whl:

Publisher: publish.yml on simon-lund/openapi-burrito

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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