Skip to main content

APItoolkit's Logo APItoolkit's Logo

Flask SDK

APItoolkit SDK PyPI - Version PyPI - Downloads Join Discord Server APItoolkit Docs

APIToolkit Flask SDK is a middleware that can be used to monitor HTTP requests, report errors and monitor 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, and more.


Table of Contents


Installation

Kindly run the command below to install the apitoolkit django sdks and necessary opentelemetry packages:

pip install apitoolkit-flask 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 flask run --app app

APItoolkit Django Configuration

After setting up open telemetry, you can now configure the apitoolkit django middleware. Next, initialize APItoolkit in your application's entry point (e.g., main.py), like so:

from flask import Flask
from apitoolkit_flask import APIToolkit

app = Flask(__name__)

# Initialize APItoolkit
apitoolkit = APIToolkit(
    service_name = "my-service",
    capture_request_body = True,
    capture_response_body = True,
)

@app.before_request
def before_request():
    apitoolkit.beforeRequest()

@app.after_request
def after_request(response):
    apitoolkit.afterRequest(response)
    return response
# END Initialize APItoolkit

@app.route('/hello', methods=['GET', 'POST'])
def sample_route():
    return {"Hello": "World"}

app.run(debug=True)

[!NOTE]

The {ENTER_YOUR_API_KEY_HERE} demo string should be replaced with the API key generated from the APItoolkit dashboard.


[!IMPORTANT]

To learn more configuration options (redacting fields, error reporting, outgoing requests, etc.), please read this SDK documentation.

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:

License

This repository is published under the MIT license.


Release files for apitoolkit-flask 1.0.3

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

Source distribution (sdist)

Source distribution for apitoolkit-flask 1.0.3
File Size Uploaded
apitoolkit_flask-1.0.3.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for apitoolkit-flask 1.0.3
File Interpreter ABI Platform
apitoolkit_flask-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 8.6 kB

Release files / apitoolkit_flask-1.0.3.tar.gz

Download URL apitoolkit_flask-1.0.3.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
35cd96d132838437a208a844256425db829c7d26372699ffd8af4270d052cb6f
BLAKE2b-256 checksum
How to use checksums
ae7cb0c662f9f9d97d496eda94e3858f69b3b78226abf0ebbbc51145c9ed902e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release files / apitoolkit_flask-1.0.3-py3-none-any.whl

Download URL apitoolkit_flask-1.0.3-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
454d90a0fe1526172a576e63961f2123feb5ce8bed88bfc318c67167e2077840
BLAKE2b-256 checksum
How to use checksums
1a4daae342448ff7a3a435a1a36bd5e231bdd685abba6067b3efb2d2036f1bdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.1

2 release files

0.4.0

2 release files

0.3.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.3

2 release files

0.1.2

2 release files

0.0.1

2 release files

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