{"id":21726254,"url":"https://github.com/albertnadal/asyncapi-schema-pydantic","last_synced_at":"2025-07-24T10:39:06.419Z","repository":{"id":57130210,"uuid":"454351839","full_name":"albertnadal/asyncapi-schema-pydantic","owner":"albertnadal","description":"Pydantic model for the AsyncAPI (v2) specification schema","archived":false,"fork":false,"pushed_at":"2023-11-14T13:29:26.000Z","size":62,"stargazers_count":14,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T23:08:17.641Z","etag":null,"topics":["asyncapi","asyncapi-schemas","asyncapi-specification","pydantic","pydantic-models"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/albertnadal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-01T10:55:04.000Z","updated_at":"2025-03-08T16:16:30.000Z","dependencies_parsed_at":"2024-11-26T03:27:26.113Z","dependency_job_id":"f58e7466-04c8-4040-83e8-3b6e41d2a537","html_url":"https://github.com/albertnadal/asyncapi-schema-pydantic","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"83966bdc11f2d465a10b52cec5ff79d18fa6f5fe"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertnadal%2Fasyncapi-schema-pydantic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertnadal%2Fasyncapi-schema-pydantic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertnadal%2Fasyncapi-schema-pydantic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertnadal%2Fasyncapi-schema-pydantic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/albertnadal","download_url":"https://codeload.github.com/albertnadal/asyncapi-schema-pydantic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248643004,"owners_count":21138355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncapi","asyncapi-schemas","asyncapi-specification","pydantic","pydantic-models"],"created_at":"2024-11-26T03:23:42.038Z","updated_at":"2025-04-12T23:08:27.083Z","avatar_url":"https://github.com/albertnadal.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# asyncapi-schema-pydantic\n\n[![pypi](https://img.shields.io/pypi/v/asyncapi-schema-pydantic.svg)](https://pypi.python.org/pypi/asyncapi-schema-pydantic)\n\nAsyncAPI (v2) specification schema as [Pydantic](https://github.com/samuelcolvin/pydantic) classes.\n\nThe naming of the classes follows the schema in \n[AsyncAPI specification](https://github.com/asyncapi/spec/blob/master/spec/asyncapi.md#schema).\n\n## Installation\n\n`pip install asyncapi-schema-pydantic`\n\n## Try me\n\n```python\nfrom asyncapi_schema_pydantic import (  AsyncAPI,\n                                        Info,\n                                        ChannelItem,\n                                        Operation,\n                                        Message,\n                                        ChannelBindings,\n                                        AmqpChannelBinding,\n                                        AmqpQueue,\n                                        Tag )\n\n# Construct AsyncAPI by pydantic objects\nasync_api = AsyncAPI(\n    info=Info(\n        title=\"Email Service\",\n        version=\"1.0.0\",\n        description='description'\n    ),\n    channels={\n        \"user/signedup\": ChannelItem(\n            description='This channel is used to exchange messages about users signing up',\n            subscribe=Operation(\n                summary='A user signed up.',\n                message=Message(\n                    name='UserSignup',\n                    title='User signup',\n                    summary='Action to sign a user up.',\n                    description='A longer description of the message',\n                    contentType='application/json',\n                    tags=[\n                        Tag(name='user'),\n                        Tag(name='signup'),\n                        Tag(name='register')\n                    ]\n                ),\n            ),\n            bindings=ChannelBindings(\n                amqp=AmqpChannelBinding(\n                    param_is='queue',\n                    queue=AmqpQueue(\n                        name='my-queue-name',\n                        durable=True,\n                        exclusive=True,\n                        autoDelete=False,\n                        vhost='/'\n                    )\n                )\n            )\n        )\n    }\n)\n\nprint(async_api.json(by_alias=True, exclude_none=True, indent=2))\n```\n\nResult:\n\n```json\n{\n  \"asyncapi\": \"2.3.0\",\n  \"info\": {\n    \"title\": \"Email Service\",\n    \"version\": \"1.0.0\",\n    \"description\": \"description\"\n  },\n  \"channels\": {\n    \"user/signedup\": {\n      \"description\": \"This channel is used to exchange messages about users signing up\",\n      \"subscribe\": {\n        \"summary\": \"A user signed up.\",\n        \"message\": {\n          \"contentType\": \"application/json\",\n          \"name\": \"UserSignup\",\n          \"title\": \"User signup\",\n          \"summary\": \"Action to sign a user up.\",\n          \"description\": \"A longer description of the message\",\n          \"tags\": [\n            {\n              \"name\": \"user\"\n            },\n            {\n              \"name\": \"signup\"\n            },\n            {\n              \"name\": \"register\"\n            }\n          ]\n        }\n      },\n      \"bindings\": {\n        \"amqp\": {\n          \"queue\": {\n            \"name\": \"my-queue-name\",\n            \"durable\": true,\n            \"exclusive\": true,\n            \"autoDelete\": false,\n            \"vhost\": \"/\"\n          }\n        }\n      }\n    }\n  }\n}\n```\n\n## Take advantage of Pydantic\n\nPydantic is a great tool, allow you to use object / dict / mixed data for for input.\n\nThe following examples give the same AsyncAPI result as above:\n\n```python\nfrom asyncapi_schema_pydantic import AsyncAPI, ChannelItem, Operation\n\n# Construct AsyncAPI from dict\nasync_api = AsyncAPI.parse_obj({\n  \"asyncapi\": \"2.3.0\",\n  \"info\": {\n    \"title\": \"Email Service\",\n    \"version\": \"1.0.0\",\n    \"description\": \"description\"\n  },\n  \"channels\": {\n    \"user/signedup\": {\n      \"description\": \"This channel is used to exchange messages about users signing up\",\n      \"subscribe\": {\n        \"summary\": \"A user signed up.\",\n        \"message\": {\n          \"contentType\": \"application/json\",\n          \"name\": \"UserSignup\",\n          \"title\": \"User signup\",\n          \"summary\": \"Action to sign a user up.\",\n          \"description\": \"A longer description of the message\"\n        }\n      }\n    }\n  }\n})\n\n# Construct AsyncAPI with mix of dict/object\nasync_api = AsyncAPI.parse_obj({\n  \"asyncapi\": \"2.3.0\",\n  \"info\": {\n    \"title\": \"Email Service\",\n    \"version\": \"1.0.0\",\n    \"description\": \"description\"\n  },\n  \"channels\": {\n    \"user/signedup\": ChannelItem(\n            description='This channel is used to exchange messages about users signing up',\n            subscribe=Operation(\n                summary='A user signed up.',\n                message={\n                  \"contentType\": \"application/json\",\n                  \"name\": \"UserSignup\",\n                  \"title\": \"User signup\",\n                  \"summary\": \"Action to sign a user up.\",\n                  \"description\": \"A longer description of the message\"\n                }\n            )\n        )\n  }\n})\n```\n\n## Load and validate an AsyncAPI specification from a YAML file\n\n```python\nfrom asyncapi_schema_pydantic import AsyncAPI\n\nasync_api = AsyncAPI.load_from_file(\"tests/data/sample.yaml\")\nprint(async_api.json(by_alias=True, exclude_none=True, indent=2))\n```\n\n## License\n\n[MIT License](https://github.com/albertnadal/asyncapi-schema-pydantic/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertnadal%2Fasyncapi-schema-pydantic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falbertnadal%2Fasyncapi-schema-pydantic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertnadal%2Fasyncapi-schema-pydantic/lists"}