FastAPI SDK
APIToolkit FastAPI SDK is a middleware that can be used to monitor incoming HTTP requests, errors and outgoing requests. It is provides additional functionalities on top of the open telemetry instrumentation which creates a custom span for each request capturing details about the request including request, response bodies, headers, status code, duration, etc.
Table of Contents
Installation
Kindly run the command below to install the apitoolkit pyramid sdks and necessary opentelemetry packages:
pip install apitoolkit-fastapi opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install
Setup Open Telemetry
Setting up open telemetry allows you to send traces, metrics and logs to the APIToolkit platform. To setup open telemetry, you need to configure the following environment variables:
OTEL_EXPORTER_OTLP_ENDPOINT="http://otelcol.apitoolkit.io:4317"
OTEL_SERVICE_NAME="my-service" # Specifies the name of the service.
OTEL_RESOURCE_ATTRIBUTES="at-project-key={ENTER_YOUR_API_KEY_HERE}" # Adds your API KEY to the resource.
OTEL_EXPORTER_OTLP_PROTOCOL="grpc" #Specifies the protocol to use for the OpenTelemetry exporter.
Then run the command below to start your server with opentelemetry instrumented:
opentelemetry-instrument python3 myapp.py
APIToolkit FastAPI Configuration
Next, initialize APItoolkit in your application's entry point (e.g., main.py), like so:
from fastapi import FastAPI
from apitoolkit_fastapi import APIToolkit
app = FastAPI()
# Initialize APItoolkit
apitoolkit = APIToolkit(service_name="my-service")
app.middleware('http')(apitoolkit.middleware)
@app.get("/")
def read_root():
return {"Hello": "World"}
Contributing and Help
To contribute to the development of this SDK or request help from the community and our team, kindly do any of the following:
- Read our Contributors Guide.
- Join our community Discord Server.
- Create a new issue in this repository.
License
This repository is published under the MIT license.
Metadata
Release files for apitoolkit-fastapi 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| apitoolkit_fastapi-2.0.0.tar.gz | 4.1 kB | Without provenance | Details for apitoolkit_fastapi-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apitoolkit_fastapi-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for apitoolkit_fastapi-2.0.0-py3-none-any.whl |
Total release size: 8.4 kB
Release files / apitoolkit_fastapi-2.0.0.tar.gz
| Download URL | apitoolkit_fastapi-2.0.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
081115981a739df1558acdc2cc337c1af2f707ac89cfca0c70a8a8ef28c5f93c
|
|
BLAKE2b-256 checksum How to use checksums |
e0b6374f420ebbf03170c08a20f49fd9d23b1a8386d24bcc67a4cbc1a6adf4c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Release files / apitoolkit_fastapi-2.0.0-py3-none-any.whl
| Download URL | apitoolkit_fastapi-2.0.0-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
81f9de58d6ae7783387ea5c8087825eb3d2409ffe40ecbb8f73ccf1ab6a62ee4
|
|
BLAKE2b-256 checksum How to use checksums |
4468bdd936be3146eca095d0cec0d7ad87a868b5bab1332b9e26a9247f3497b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Security for apitoolkit-fastapi 2.0.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.