Skip to main content

Multi-language SDK generator from OpenAPI specifications

Project description

SDKGen Logo

SDKGen

Multi-language SDK Generator from OpenAPI Specifications

Type-safe • Async-first • Made for developers


Python 3.12+ License: MIT Build Status

Quick StartFeaturesDocumentationContributing


✨ Features

  • 🚀 Multi-language support - Python (TypeScript, Go, Rust planned)
  • 🎯 Type-safe - Full type hints and TypedDict support
  • Async-first - Modern async patterns with httpx
  • 🧩 Complete OpenAPI 3.x - $ref resolution, allOf/oneOf/anyOf, discriminators
  • 📦 Clean SDK structure - Dataclass-based, resource-oriented
  • 🔧 Smart method naming - Intelligent CRUD + RPC action detection
  • 🌐 Namespace support - API versioning (v1, v2, beta)
  • 🔐 Auth built-in - Bearer, API Key, OAuth2

📦 Installation

# Install from PyPI
pip install sdkgen

# Or using uv (recommended)
uv pip install sdkgen

# For development
git clone https://github.com/4thel00z/sdkgen
cd sdkgen
uv install

⚙️ Configuration

SDKGen works with any OpenAPI 3.x specification:

# From local file
sdkgen generate -i openapi.yaml -o ./my-sdk -l python

# From URL
sdkgen generate -i https://api.example.com/openapi.json -o ./my-sdk

# With custom package name
sdkgen generate -i spec.yaml -o ./sdk --package-name my_custom_sdk

🚀 Quick Start

1. Generate SDK from OpenAPI Spec

# Generate Python SDK
sdkgen generate \
  --input https://api.example.com/openapi.yaml \
  --output ./my-sdk \
  --language python \
  --package-name my_api_sdk

2. Use Generated SDK

import asyncio
from my_sdk import Client

async def main():
    # Initialize client (reads from environment variables)
    client = Client(
        base_url="https://api.example.com",
        api_key="your-api-key"
    )

    # List resources with type-safe parameters
    users = await client.v1.users.list(page=0, size=10)
    print(f"Found {len(users)} users")

    # Create resource
    user = await client.v1.users.create(
        name="John Doe",
        email="john@example.com"
    )

    # Get by ID
    user = await client.v1.users.get(user_id="123")

    # Update
    updated = await client.v1.users.update(
        user_id="123",
        name="Jane Doe"
    )

    # Delete
    await client.v1.users.delete(user_id="123")

    # RPC-style actions
    pdf = await client.v1.files.download(file_id="abc")

asyncio.run(main())

🎯 Generated SDK Structure

SDKGen creates clean, maintainable SDK code:

my_sdk/
├── __init__.py
├── client.py          # Main Client dataclass
├── models.py          # TypedDict models + converters
├── utils.py           # Utility functions
└── resources/
    ├── __init__.py
    ├── v1.py          # V1 namespace
    ├── users.py       # Users resource
    └── files.py       # Files resource

🛡️ Type Safety

Generated SDKs use TypedDict for full type safety:

from my_sdk.models import CreateUserInput, User

# Type-safe input (IDE autocomplete works!)
user_data: CreateUserInput = {
    "name": "John",
    "email": "john@example.com",
    "age": 30  # Optional field
}

user: User = await client.v1.users.create(**user_data)

📚 API Resources

Supported OpenAPI Features

  • ✅ $ref resolution (local and remote with caching)
  • ✅ Schema composition (allOf, oneOf, anyOf)
  • ✅ Discriminators for polymorphic types
  • ✅ Path, query, header, cookie parameters
  • ✅ Request bodies (JSON, form-data, multipart, binary)
  • ✅ Multiple response types
  • ✅ Authentication schemes (Bearer, API Key, OAuth2)
  • ✅ Tags for resource grouping
  • ✅ API versioning namespaces (v1, beta)
  • ✅ Enums (string and integer)
  • ✅ Nested resources
  • ✅ Pagination patterns

Method Naming Intelligence

SDKGen uses a 3-priority system for clean, intuitive method names:

  1. Clean operationId - Extracts from OpenAPI operationId
  2. RPC-style actions - Detects 35+ action verbs (download, activate, export, etc.)
  3. HTTP method + response - Smart CRUD naming based on method and response type

Examples:

  • POST /api/v1/usersclient.v1.users.create()
  • GET /api/v1/users (array) → client.v1.users.list()
  • GET /api/v1/users/{id} (object) → client.v1.users.get(id)
  • GET /api/v1/files/{id}/downloadclient.v1.files.download(id)
  • GET /healthclient.health()

🧪 Testing

# Validate OpenAPI spec
sdkgen validate -i openapi.yaml

# Show intermediate representation (debug)
sdkgen show-ir -i openapi.yaml

# Generate and test
sdkgen generate -i spec.yaml -o ./test-sdk
cd test-sdk && python -m py_compile **/*.py

🔧 Development

# See all available commands
make help

# Install dependencies
make dev

# Run all quality checks
make check

# Format code
make format

# Run linter
make lint

# Type check
make typecheck

# Test SDK generation
make test-sdk

📖 Documentation

🤝 Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

# Quick start
make dev
make check

📄 License

MIT License - see LICENSE file for details.


Built with ❤️ for the developer community

GitHubDocumentationIssues

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

sdkgen-0.1.3.tar.gz (98.2 kB view details)

Uploaded Source

Built Distribution

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

sdkgen-0.1.3-py3-none-any.whl (42.4 kB view details)

Uploaded Python 3

File details

Details for the file sdkgen-0.1.3.tar.gz.

File metadata

  • Download URL: sdkgen-0.1.3.tar.gz
  • Upload date:
  • Size: 98.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for sdkgen-0.1.3.tar.gz
Algorithm Hash digest
SHA256 bebd879c76c8725c4547cbe6da434ffa43368558a589aafd228e315be62cc2b3
MD5 c782e4469dcd48c68384ed71e0f6ae29
BLAKE2b-256 93f0e6c71bd262bfa0ede99b7e9e4bd82b796b53e64cb27e6bad5cf657d7a89d

See more details on using hashes here.

File details

Details for the file sdkgen-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: sdkgen-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 42.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for sdkgen-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6249a5918a8976e25dce86a9f248b374d499678e134192ac89c69a4e696e1644
MD5 b2f6a5eca7b98f54a0f0d7940bbc92fa
BLAKE2b-256 1415d7b7bd2e7d67dd54c528fc60e99fbaddb0b768977959e76fa340e6919e4e

See more details on using hashes here.

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