The repository for our open source Python middleware can be found here.
Install with pip:
pip install apilytics
Install with poetry:
poetry add apilytics
Enable the middleware and set your API key:
A good practice is to securely store the API key as an environment variable.
You can leave the env variable unset in e.g. development and test environments,
the middleware will be automatically disabled if the key is
# settings.py import os APILYTICS_API_KEY = os.getenv("APILYTICS_API_KEY") MIDDLEWARE = [ "apilytics.django.ApilyticsMiddleware", # Ideally the first middleware in the list. # ... ]
# main.py import os from apilytics.fastapi import ApilyticsMiddleware from fastapi import FastAPI app = FastAPI() # Ideally last first middleware you add. app.add_middleware(ApilyticsMiddleware, api_key=os.getenv("APILYTICS_API_KEY"))
# app.py import os from apilytics.flask import apilytics_middleware from flask import Flask app = Flask(__name__) # Ideally wrap your app with the middleware before you do anything else with it. app = apilytics_middleware(app, api_key=os.getenv("APILYTICS_API_KEY"))
Other Python Frameworks
# my_apilytics_middleware.py import os from apilytics.core import ApilyticsSender def my_apilytics_middleware(request, get_response): api_key = os.getenv("APILYTICS_API_KEY") if not api_key: return get_response(request) with ApilyticsSender( api_key=api_key, path=request.path, query=request.query_string, method=request.method, request_size=len(request.body), user_agent=request.headers.get("user-agent"), ) as sender: response = get_response(request) sender.set_response_info( status_code=response.status_code, response_size=len(response.body), ) return response
Help us improve these docs by giving us feedback.
Easy to use
API monitoring doesn't have to be hard. Unfortunately with the most tools out there, that is the case though. Apilytics is here to fix that. Our 5-minute installation is one of the corner stones why you should pick Apilytics.
Apilytics middlewares are super lightweight, fast and they will cause no performance impact on your APIs whatsoever.
Our privacy-friendly approach lets you be in control of your data, making Apilytics a great fit for anyone aware of their privacy. Our open source middlewares allow you to see exactly what data leaves your servers.
We want to be transparent on how we process the data of our users. This is why we have open sourced 100% of our client middleware code, keeping our users updated on what data from their API is processed.