Skip to main content

Automatic avro wire protocol support for FastAPI

Project description

AvroFastAPI Logo
python-package.yml workflow pypi package version

Add Avro encoding support to your FastAPI application with a one-line setup

- app = FastAPI()
+ app = AvroFastAPI()

Installation

pip install avrofastapi

Usage

SERVER

from avrofastapi import AvroFastAPI
from datetime import datetime, timezone
from pydantic import BaseModel


app = AvroFastAPI()

class TestResponseModel(BaseModel) :
	A: str
	B: int
	C: datetime


@app.get('/', response_model=TestResponseModel)
def v1Example() :
	return TestResponseModel(
		A='ayy',
		B=1337,
		C=datetime.now(timezone.utc),
	)


if __name__ == '__main__' :
	from uvicorn.main import run
	run(app, host='0.0.0.0', port=5000)

CLIENT

from avrofastapi.gateway import Gateway
from datetime import datetime
from pydantic import BaseModel
import requests
import asyncio

class TestResponseModel(BaseModel) :
	A: str 
	B: int
	C: datetime

requests.get('http://localhost:5000/').json()
# returns: {'A': 'ayy', 'B': 1337, 'C': '2023-01-22T10:01:00.543317+00:00'}

gateway = Gateway('http://localhost:5000/', 'v1Example__get', response_model=TestResponseModel)
asyncio.run(gateway())
# returns: TestResponseModel(A='ayy', B=1337, C=datetime.datetime(2023, 1, 22, 10, 2, 29, 641314, tzinfo=<avro.timezones.UTCTzinfo object at 0x7efbe9cdb580>))

Development

Fork the parent repository at https://github.com/kheina-com/avrofastapi and edit like any other python project.
Tests are run with pytest in the command line and input sorting is run via isort .

License

This work is licensed under the Mozilla Public License 2.0, allowing for public, private, and commercial use so long as access to this library's source code is provided. If this library's source code is modified, then the modified source code must be licensed under the same license or an applicable GNU license and made publicly available.

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

avrofastapi-0.0.5.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

avrofastapi-0.0.5-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

Details for the file avrofastapi-0.0.5.tar.gz.

File metadata

  • Download URL: avrofastapi-0.0.5.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for avrofastapi-0.0.5.tar.gz
Algorithm Hash digest
SHA256 f110e10dba575ce7eb25f328d16d1e97c6c94cdbbec3fdf7632e3eb2d64a29fd
MD5 25062fed387d8bce1f4d5e82881352d5
BLAKE2b-256 f9ab9f9faa4bd8bd17a40242198767e6ff724a23e47903bda8a1ead4eedd3062

See more details on using hashes here.

File details

Details for the file avrofastapi-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: avrofastapi-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 28.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for avrofastapi-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0852cf0fb445f890d2a3fde64b4c5978bcac83d1442762346c7bb8b060ac0f22
MD5 6d340943e77dcaec759c0a25b2fb2340
BLAKE2b-256 b63b42486eb6a4dea9d4d3501d90d55898f4649a157673340d99936099f16f4a

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