django-api-orm Documentation

Tests Coverage Python Version License

A Django ORM-like interface for external REST APIs with Pydantic validation and httpx.

django-api-orm provides a familiar Django ORM interface for interacting with REST APIs, making it easy to work with external services using the same patterns you already know.

Key Features

  • Sync and Async Support - Use synchronous or asynchronous clients based on your needs

  • Type Safety - Full type hints and Pydantic validation throughout

  • Django-like API - Familiar filter(), exclude(), get(), first(), last(), etc.

  • HTTP/2 Support - Optional HTTP/2 for better performance (async only)

  • Connection Pooling - Built-in connection pooling with httpx

  • Lazy Evaluation - QuerySets only execute when needed

  • Full CRUD - Complete create, read, update, delete operations

  • 91% Test Coverage - 152 comprehensive tests

Quick Example

from pydantic import BaseModel
from django_api_orm import APIModel, ServiceClient, register_models

# Define your schema
class UserSchema(BaseModel):
    id: int | None = None
    name: str
    email: str
    active: bool = True

# Define your model
class User(APIModel):
    _schema_class = UserSchema
    _endpoint = "/api/v1/users/"

# Use it!
with ServiceClient(base_url="https://api.example.com") as client:
    register_models(client, User)

    # Django-like queries
    users = User.objects.filter(active=True)
    for user in users:
        print(f"{user.name} - {user.email}")

    # CRUD operations
    user = User.objects.get(id=1)
    user.email = "newemail@example.com"
    user.save()

Documentation Contents

Development

Indices and tables