https://github.com/SMLTTECH/django-asyncapi
AsyncAPI ✨ documentation in django via pydantic models
https://github.com/SMLTTECH/django-asyncapi
asyncapi django pydantic python
Last synced: about 2 months ago
JSON representation
AsyncAPI ✨ documentation in django via pydantic models
- Host: GitHub
- URL: https://github.com/SMLTTECH/django-asyncapi
- Owner: SMLTTECH
- Created: 2023-12-28T18:06:56.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-20T17:29:42.000Z (9 months ago)
- Last Synced: 2024-07-29T16:59:28.372Z (9 months ago)
- Topics: asyncapi, django, pydantic, python
- Language: Python
- Homepage: https://skonik.github.io/django-asyncapi/
- Size: 1.15 MB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```python
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, Fieldclass 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: Customerclass 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.
2. Add `djanog-asyncapi` to `INSTALLED_APPS`
```python
INSTALLED_APPS = [
...,
"django_asyncapi",
]
```3. Setup configuration inside `settings.py`
```pythonDJANGO_ASYNCAPI = {
"ASYNCAPI_SPEC_CLASS": "bus.routing.MySpecialServiceAsyncAPISpecV3",
}
```4. Add `django-asyncapi` urls
```python
from django.urls import path, includeurlpatterns = [
path('docs/', include('django_asyncapi.urls')),
]```
5. Enjoy your results by opening `docs/asyncapi/v3`
