An easy to use, integrated client for FastApi,
- Uses the same decorators as FastApi
- Dose not require one to "recreate" clients and works out of the box.
- Allows defining the client "host" via the
with
command. - Works with async as well.
- Dose not affect the operation of the api in any way.
This repo is in beta mode, some bugs may still exist and test coverage is not complete. PR's welcome.
To use the client, you must enable it on the api before defining the api methods
from fastapi import FastAPI
from fastapi_client import FastAPIClient
api = FastAPI()
# This is REQUIRED in order to allow the fast api client to wrap around any function calls.
# NOTE: The client DOSE NOT AFFECT the operation of the API, and dose not slow it down
# in any way.
FastAPIClient.enable(api)
@api.get("/echo")
def echo(a: int, b: int):
rslt = a + b
print(rslt)
return rslt
We then can (async methods, just add async),
from test_module import echo
from fastapi_client import FastAPIClient
# Call the function locally
echo(1,2)
# Call the function on the server running in localhost
with FastAPIClient("localhost:8080"):
print(echo(1, 2))
pip install fastapi_client
Feel free to ping me in issues or directly on LinkedIn to contribute.
Copyright © Zav Shotan
and other contributors.
It is free software, released under the MIT licence, and may be redistributed under the terms specified in LICENSE.