88[ ![ python versions] ( https://img.shields.io/pypi/pyversions/apilytics )] ( #what-python-versions-does-the-package-work-with )
99[ ![ license] ( https://img.shields.io/pypi/l/apilytics.svg )] ( https://github.com/apilytics/apilytics-python/blob/master/LICENSE )
1010
11+ Apilytics is a service that lets you analyze operational, performance and security metrics from your APIs without infrastructure-level logging.
12+
13+ <img src =" https://www.apilytics.io/mock-ups/time-frame.gif " alt =" Apilytics dashboard animation " width =" 600 " height =" 300 " />
14+
1115## Installation
1216
13171 . Sign up and get your API key from https://apilytics.io - we offer a completely free trial with no credit card required!
@@ -22,7 +26,7 @@ pip install apilytics
2226You can leave the env variable unset in e.g. development and test environments,
2327the middleware will be automatically disabled if the key is ` None ` .*
2428
25- ### Django:
29+ ### Django
2630
2731` settings.py ` :
2832``` python
@@ -35,7 +39,7 @@ MIDDLEWARE = [
3539]
3640```
3741
38- ### FastAPI:
42+ ### FastAPI
3943
4044` main.py ` :
4145
@@ -50,7 +54,7 @@ app = FastAPI()
5054app.add_middleware(ApilyticsMiddleware, api_key = os.getenv(" APILYTICS_API_KEY" ))
5155```
5256
53- ### Other Python Frameworks:
57+ ### Other Python Frameworks
5458
5559You can easily build your own middleware which measures the execution time and sends the metrics:
5660
@@ -62,14 +66,18 @@ from apilytics.core import ApilyticsSender
6266
6367
6468def my_apilytics_middleware (request , get_response ):
65- with ApilyticsSender(
66- api_key = os.getenv(" APILYTICS_API_KEY" ),
67- path = request.path,
68- method = request.method,
69- ) as sender:
70- response = get_response(request)
71- sender.set_response_info(status_code = response.status_code)
72- return response
69+ api_key = os.getenv(" APILYTICS_API_KEY" )
70+ if not api_key:
71+ return get_response(request)
72+
73+ with ApilyticsSender(
74+ api_key = api_key,
75+ path = request.path,
76+ method = request.method,
77+ ) as sender:
78+ response = get_response(request)
79+ sender.set_response_info(status_code = response.status_code)
80+ return response
7381```
7482
7583## Frequently Asked Questions
0 commit comments