Python
Setup guide for Django REST FrameworkJust a few simple steps to get started with Apitally.
This page guides you through the steps of configuring your Django REST Framework (DRF) application to work with Apitally. If you don’t have an account yet, now would be a good time to sign up. Once you’re done with this guide, you will be able to:prod
and dev
) for your app, or simply accept the defaults. Take a note of the client ID displayed after submitting. You will need it in the next step. Add middlewareNext, install the Apitally SDK in your project with the extra.
pip install "apitally[django_rest_framework]"
Activate the Apitally middleware in your Django application by appending it to the end of the MIDDLEWARE
list in your Django settings. Then configure the Apitally middleware by adding APITALLY_MIDDLEWARE
to your settings file and including the client_id
for your app. You’ll find the client_id
on the Setup instructions page for your app in the Apitally dashboard, which is displayed immediately after creating the app.
MIDDLEWARE = [
"apitally.django.ApitallyMiddleware",
# Other middleware ...
]
APITALLY_MIDDLEWARE = {
"client_id": "your-client-id",
"env": "dev", # or "prod" etc.
"include_django_views": False, # Set to True to include regular Django views
}
If you’re using uWSGI to serve your app in production, make sure to run it with the--enable-threads
and --lazy-apps
options. Otherwise the Apitally client won’t work correctly.
At this point the basic setup for your application is complete and you will start seeing data in the Apitally dashboard.
Identify consumersTo analyze and filter API traffic by consumers, you can associate requests with consumer identifiers in your application. In most cases, use the authenticated identity to identify the consumer. The identifier should be a string, such as a username, email address, or any other unique identifier. Optionally, you can also provide a display name and group for each consumer. To associate requests with consumers, provide a callback function in the middleware settings that takes aHttpRequest
object as an argument and returns a consumer identifier, an ApitallyConsumer
object or None
.
from django.http import HttpRequest
def identify_consumer(request: HttpRequest) -> str | None:
if request.user.is_authenticated:
return request.user.username
return None
The Consumers dashboard now shows all consumers that have made requests to your application. You can also filter other dashboards by consumer.
Configure request loggingLogging of individual requests and responses is disabled by default to protect potentially sensitive data. If you enable it, you can configure in detail what parts of the request and response should be logged. You can also mask sensitive information (e.g. in headers) and exclude certain requests from logging. The SDK applies default masking rules for common sensitive headers, query parameters and request/response body fields.APITALLY_MIDDLEWARE = {
"client_id": "your-client-id",
"env": "dev", # or "prod" etc.
"enable_request_logging": True,
"log_request_headers": True,
"log_request_body": True,
"log_response_body": True,
"capture_logs": True,
}
The Request logs dashboard now shows individual requests handled by your application. You can filter, search, and inspect them in detail.
Advanced settingsinclude_django_views
to True
. Useful if your API includes endpoints not implemented using DRF.urlconfs
parameter to a list of Django URL configuration modules you’d like to include.APITALLY_MIDDLEWARE = {
"client_id": "your-client-id",
"env": "dev", # or "prod" etc.
"include_django_views": True,
"urlconfs": ["your_project.api.urls"],
}
Known issues
preload_app
must be set to False
. Otherwise, the Apitally client will not work correctly.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4