asyncapi-schema-pydantic
AsyncAPI (v2) specification schema as Pydantic classes.
The naming of the classes follows the schema in AsyncAPI specification.
Installation
pip install asyncapi-schema-pydantic
Try me
from asyncapi_schema_pydantic import ( AsyncAPI,
Info,
ChannelItem,
Operation,
Message,
ChannelBindings,
AmqpChannelBinding,
AmqpQueue,
Tag )
# Construct AsyncAPI by pydantic objects
async_api = AsyncAPI(
info=Info(
title="Email Service",
version="1.0.0",
description='description'
),
channels={
"user/signedup": ChannelItem(
description='This channel is used to exchange messages about users signing up',
subscribe=Operation(
summary='A user signed up.',
message=Message(
name='UserSignup',
title='User signup',
summary='Action to sign a user up.',
description='A longer description of the message',
contentType='application/json',
tags=[
Tag(name='user'),
Tag(name='signup'),
Tag(name='register')
]
),
),
bindings=ChannelBindings(
amqp=AmqpChannelBinding(
param_is='queue',
queue=AmqpQueue(
name='my-queue-name',
durable=True,
exclusive=True,
autoDelete=False,
vhost='/'
)
)
)
)
}
)
print(async_api.json(by_alias=True, exclude_none=True, indent=2))
Result:
{
"asyncapi": "2.3.0",
"info": {
"title": "Email Service",
"version": "1.0.0",
"description": "description"
},
"channels": {
"user/signedup": {
"description": "This channel is used to exchange messages about users signing up",
"subscribe": {
"summary": "A user signed up.",
"message": {
"contentType": "application/json",
"name": "UserSignup",
"title": "User signup",
"summary": "Action to sign a user up.",
"description": "A longer description of the message",
"tags": [
{
"name": "user"
},
{
"name": "signup"
},
{
"name": "register"
}
]
}
},
"bindings": {
"amqp": {
"queue": {
"name": "my-queue-name",
"durable": true,
"exclusive": true,
"autoDelete": false,
"vhost": "/"
}
}
}
}
}
}
Take advantage of Pydantic
Pydantic is a great tool, allow you to use object / dict / mixed data for for input.
The following examples give the same AsyncAPI result as above:
from asyncapi_schema_pydantic import AsyncAPI, ChannelItem, Operation
# Construct AsyncAPI from dict
async_api = AsyncAPI.parse_obj({
"asyncapi": "2.3.0",
"info": {
"title": "Email Service",
"version": "1.0.0",
"description": "description"
},
"channels": {
"user/signedup": {
"description": "This channel is used to exchange messages about users signing up",
"subscribe": {
"summary": "A user signed up.",
"message": {
"contentType": "application/json",
"name": "UserSignup",
"title": "User signup",
"summary": "Action to sign a user up.",
"description": "A longer description of the message"
}
}
}
}
})
# Construct AsyncAPI with mix of dict/object
async_api = AsyncAPI.parse_obj({
"asyncapi": "2.3.0",
"info": {
"title": "Email Service",
"version": "1.0.0",
"description": "description"
},
"channels": {
"user/signedup": ChannelItem(
description='This channel is used to exchange messages about users signing up',
subscribe=Operation(
summary='A user signed up.',
message={
"contentType": "application/json",
"name": "UserSignup",
"title": "User signup",
"summary": "Action to sign a user up.",
"description": "A longer description of the message"
}
)
)
}
})
Load and validate an AsyncAPI specification from a YAML file
from asyncapi_schema_pydantic import AsyncAPI
async_api = AsyncAPI.load_from_file("tests/data/sample.yaml")
print(async_api.json(by_alias=True, exclude_none=True, indent=2))
License
Metadata
Release files for asyncapi-schema-pydantic 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| asyncapi-schema-pydantic-1.0.1.tar.gz | 35.7 kB | Without provenance | Details for asyncapi-schema-pydantic-1.0.1.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asyncapi_schema_pydantic-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for asyncapi_schema_pydantic-1.0.1-py3-none-any.whl |
| asyncapi_schema_pydantic-1.0.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for asyncapi_schema_pydantic-1.0.1-py2.py3-none-any.whl |
Total release size: 145.0 kB
Release files / asyncapi-schema-pydantic-1.0.1.tar.gz
| Download URL | asyncapi-schema-pydantic-1.0.1.tar.gz |
|---|---|
| Size | 35.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d8eccba006bc95958f80df462d6ae264f4fecdfe45a1087ef27b50c5010f852
|
|
BLAKE2b-256 checksum How to use checksums |
c5c82cbf5649d1c9bfa5adfa60d73b54f2f88abb83b1abf6cfd3638873b582ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.13
|
Release files / asyncapi_schema_pydantic-1.0.1-py3-none-any.whl
| Download URL | asyncapi_schema_pydantic-1.0.1-py3-none-any.whl |
|---|---|
| Size | 54.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0279183596f0f046900c061ebdc5c29be60da208086922c6971f2729d735f9df
|
|
BLAKE2b-256 checksum How to use checksums |
ab72689c5ffbe2b09186704e498e647f12898576fbd7191e133b280803b1a326
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.13
|
Release files / asyncapi_schema_pydantic-1.0.1-py2.py3-none-any.whl
| Download URL | asyncapi_schema_pydantic-1.0.1-py2.py3-none-any.whl |
|---|---|
| Size | 54.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b1c6b8a5af4fdee13cabb78e63d917cc5e36024bf84f397c6c58eb194c91ba3d
|
|
BLAKE2b-256 checksum How to use checksums |
05a75d08a822f2d2917f97f0a4c0ffccd60e221d723a3a5edb9226dad3fba13e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.13
|
Security for asyncapi-schema-pydantic 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.