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.1.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

django_asyncapi-0.3.1-py3-none-any.whl (1.2 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_asyncapi-0.3.1.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • 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.1.tar.gz
Algorithm Hash digest
SHA256 83e13e6d082d7003ea767b3adaf17f646c44da05d9751bfaf3f77917045aedda
MD5 9b6771a8da67506baac62a0e8efe3799
BLAKE2b-256 e7160057093df1ed37b40499c0df6b0ce355982ca75ee79fa070eac2ac4a5155

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_asyncapi-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 1.2 MB
  • 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9c6e7ae88e5ac841f98c2aa26e5890cad66e9a08759fb3a762be7e6e8f2e85b1
MD5 f6b61b04ddb59ec89933883bf21a8e30
BLAKE2b-256 64d87d2c12ebbe4fd867f89f93ee9b68c0c87d1d4e5a02a15fd3a969f8622613

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