A client for the fastapi environment
Project description
FastAPIClient
An easy to use, integrated client for FastApi,
- Uses the same decorators as FastApi
- Dose not require you to redefine the api.
- 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.
- Can be applied either globally or for a specific api (if predefined - see below).
BETA
This repo is in beta mode, some bugs may still exist and test coverage is not complete. PR's welcome.
TL;DR
To use the client, you must enable it before defining/importing the api methods
If we are using the api api_module
defined below,
from fastapi import FastAPI
api = FastAPI()
@api.get("/echo")
def echo(a: int, b: int):
rslt = a + b
print(rslt)
return rslt
We can use the client
from fastapi_client import FastAPIClient, enable_fastapi_client
# 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.
enable_fastapi_client()
from api_module import {
echo
}
# Call the function locally
echo(1,2)
# Call the function on the server running in localhost
with FastAPIClient("localhost:8080"):
print(echo(1, 2))
Non global configuration
To define an api client that works only on a specific api/router, you must enable the api client on the api object before defining the api functions,
from fastapi import FastAPI
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
Install
pip install fastapi_client
Contribution
Feel free to ping me for issues or submit a PR to contribute.
License
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for fastapi_client-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8839783d84f16a784ba4fb56b58d559a6c55df2f21b6040971ef429a2727f239 |
|
MD5 | d90b0a3dcf26801f8c0f863a358916bd |
|
BLAKE2b-256 | 9f7985c13fcc8e5bfd43a3e2d2a56fd0e4ce22415a5085eb058ba65b7c0537f3 |