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.0.tar.gz (21.3 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.0-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openapi_burrito-0.1.0.tar.gz
  • Upload date:
  • Size: 21.3 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.0.tar.gz
Algorithm Hash digest
SHA256 15536fa1a0ba25567113810ecb85c6e0b75795b07a3e1ef2599b3efad5563289
MD5 361937699f3c64c50e74058ece0ade24
BLAKE2b-256 daa34b063d5d2c37abc325822feb9d6544ee0180f84f0888040c0b2d45b05303

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_burrito-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openapi_burrito-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89e518f0590f648967db65782ccedf90dae06627ad238f4c29768b42ac7175c7
MD5 c63868e4828b0e167e105437be743b3a
BLAKE2b-256 c190079f99abbb3a1f43722c372fef5632f6788ba9d9259bbcbcd75af4f3d750

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_burrito-0.1.0-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