Skip to main content

FastAPIClient

An easy to use, integrated client for FastApi,

  1. Uses the same decorators as FastApi
  2. Dose not require you to redefine the api.
  3. Allows defining the client "host" via the with command.
  4. Works with async as well.
  5. Dose not affect the operation of the api in any way.
  6. 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.

Metadata

Release files for fastapi-client 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-client 0.1.0
File Size Uploaded Provenance Actions
fastapi_client-0.1.0.tar.gz 8.6 kB Without provenance Details for fastapi_client-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-client 0.1.0
File Interpreter ABI Platform Actions
fastapi_client-0.1.0-py3-none-any.whl Python 3 none any Details for fastapi_client-0.1.0-py3-none-any.whl

Total release size: 17.7 kB

Release files / fastapi_client-0.1.0.tar.gz

Download URL fastapi_client-0.1.0.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b6783dc3cabd5361c42762fd38a90d5163293e302f9ef5741257faa19520d3d0
BLAKE2b-256 checksum
How to use checksums
7c0200db46a13f0f9b06e2788e711a01ee48d01196f73ddf272fb3e9907f1f54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.14

Release files / fastapi_client-0.1.0-py3-none-any.whl

Download URL fastapi_client-0.1.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8839783d84f16a784ba4fb56b58d559a6c55df2f21b6040971ef429a2727f239
BLAKE2b-256 checksum
How to use checksums
9f7985c13fcc8e5bfd43a3e2d2a56fd0e4ce22415a5085eb058ba65b7c0537f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.14

Security for fastapi-client 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page