Giter Site home page Giter Site logo

avrofastapi's Introduction

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.

avrofastapi's People

Contributors

kheina avatar kheina0 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.