Skip to main content

No project description provided

Project description

django-asyncapi

Generate and host your asyncapi specification using pydantic models

Installation

Install django-asyncapi using pip or poetry:

poetry add django-asyncapi

Usage

  1. Create specification
from asyncapi_container.asyncapi.spec.v3.info import Info
from asyncapi_container.containers.v3.simple_spec import SimpleSpecV3
from asyncapi_container.custom_types import RoutingMap
from pydantic import BaseModel, Field


class Customer(BaseModel):
    first_name: str = Field(..., title='First Name')
    last_name: str = Field(..., title='Last Name')
    email: str = Field(..., title='Email')
    country: str = Field(..., title='Country')
    zipcode: str = Field(..., title='Zipcode')
    city: str = Field(..., title='City')
    street: str = Field(..., title='Street')
    apartment: str = Field(..., title='Apartment')


class OrderSchemaV1(BaseModel):
    product_id: int = Field(..., title='Product Id')
    quantity: int = Field(..., title='Quantity')
    customer: Customer


class MySpecialServiceAsyncAPISpecV3(SimpleSpecV3):
    info: Info = Info(
        title="My special Service",
        version="1.0.0",
        description="Service for making orders"
    )
    sends: RoutingMap = {
        "shop.orders.v1": [
            OrderSchemaV1,
        ]
    }
    receives: RoutingMap = {}

"shop.orders.v1" means topic to which our service produces(sends) message described as OrderSchemaV1 pydantic model.

  1. Add djanog-asyncapi to INSTALLED_APPS
INSTALLED_APPS = [
    ...,
    "django_asyncapi",
]
  1. Setup configuration inside settings.py
DJANGO_ASYNCAPI = {
    "ASYNCAPI_SPEC_CLASS": "bus.routing.MySpecialServiceAsyncAPISpecV3",
}
 
  1. Add django-asyncapi urls
from django.urls import path, include

urlpatterns = [
    path('docs/', include('django_asyncapi.urls')),
]
  1. Enjoy your results by opening docs/asyncapi/v3

alt text

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

django_asyncapi-0.3.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

django_asyncapi-0.3.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file django_asyncapi-0.3.0.tar.gz.

File metadata

  • Download URL: django_asyncapi-0.3.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/22.3.0

File hashes

Hashes for django_asyncapi-0.3.0.tar.gz
Algorithm Hash digest
SHA256 880ce0350d59cee1c75bd0559e0327873e8b3ab78480421721df62ae19134aa9
MD5 e7960714b20dea6675f0ace4e73c9175
BLAKE2b-256 31893cafa03fce0c297e261c320392c023a22c121c1025efcdcbf4be169a8866

See more details on using hashes here.

File details

Details for the file django_asyncapi-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: django_asyncapi-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/22.3.0

File hashes

Hashes for django_asyncapi-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51be6bec51f73aacd98abab616cecef34911674703dffa569be23bd16c65f706
MD5 85f8f3fe2339e445dadf27652a806cdb
BLAKE2b-256 6cd8b271c7a441e75c6d754f27923c5ff7d4ccb38386a8f797bfbc9500283ce1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page