Overview
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. 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 |
---|
|
This middleware should be added after any logging middleware and before other
middleware or application code.
Request Flow
│
┌───────────────────────────────────┐ │
│ Logging Middleware │ │
└───────────────────────────────────┘ │
┌───────────────────────────────────┐ │
│ Api Protect Middleware │ │
└───────────────────────────────────┘ │
┌───────────────────────────────────┐ │
│ Other Middleware │ │
└───────────────────────────────────┘ │
│
▼
|
Example using Falcon middleware
Code Block |
---|
# example using Falcon applicationmiddleware
from apiprotect.middleware import ApiProtectFalconMiddleware
app = falcon.App(
middleware=[
CloudTraceMiddleware(),
ApiProtectFalconMiddleware(),
SqlAlchemySessionMiddleware(),
CORSMiddleware(),
]
) |
Example using WSGI middleware
Code Block |
---|
|
# example using WSGI applicationmiddleware
from apiprotect.middleware import ApiProtectWSGIMiddleware
wsgi_app = get_wsgi_application()
protected_wsgi_app = ApiProtectWSGIMiddleware(wsgi_app)
|
...
Setting the environment variable is the preferred way, but if you need to pass it to the middleware, here is how to do that:
Example passing client_id to Falcon middleware
Code Block |
---|
|
# example passing client_id to Falcon middleware
import settings # file-based secure settings management
app = falcon.App(
middleware=[
CloudTraceMiddleware(),
ApiProtectFalconMiddleware(client_id=settings.client_id),
SqlAlchemySessionMiddleware(),
CORSMiddleware(),
]
) |
Example passing client_id to WSGI middleware
Code Block |
---|
|
# example passing client_id to WSGI middleware
import settings # file-based secure settings management
from apiprotect.middleware import ApiProtectWSGIMiddleware
wsgi_app = get_wsgi_application()
protected_wsgi_app = ApiProtectWSGIMiddleware(wsgi_app, client_id=settings.client_id) |
...