...
The Data Theorem API Protect Python SDK is a Python library that provides protection for APIs written in Python.
The SDK integrates with your Python API using the API Protect middleware which supports most popular Python frameworks, including:
Every other WSGI framework
To Protect an API, all the API developer needs to do is add the API Protect middleware to their web application code set the client Id we provide.
...
Code Block | ||
---|---|---|
| ||
""" wsgi.py For more information see https://flask.palletsprojects.com/en/2.1.x/quickstart/#hooking-in-wsgi-middleware """ from flask import Flask from apiprotect.middleware import ApiProtectWSGIMiddleware app = Flask(__name__) # Override the app wsgi_app property app.wsgi_app = ApiProtectWSGIMiddleware(app.wsgi_app) @app.route('/') def hello_world(): return 'Hello, World!' |
Example using the WSGI middleware with Django
Code Block | ||
---|---|---|
| ||
""" wsgi.py It exposes the WSGI callable as a module-level variable named ``application``. For more information see https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/ """ from django.core.wsgi import get_wsgi_application from apiprotect.middleware import ApiProtectWSGIMiddleware application = get_wsgi_application() application = ApiProtectWSGIMiddleware(application) |
...
For each API you protect Data Theorem provides a unique identifier which authenticates the SDK when it communicates with our services.
The client id we provide can be set in two way, either:
via an environment variable
DT_API_PROTECT_CLIENT_ID
or by passing it directly to the middleware. Setting the environment variable is the preferred method.
Note: If the client id is present either as the DT_API_PROTECT_CLIENT_ID
environment variable, or passed to the middleware, API Protect will activate. If the client_id cannot be easily unset but you do not wish to activate API Protect, you can set DT_API_PROTECT_DEACTIVATE=True
to prevent the service from activating.
...