Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/treblle/treblle-flask
The official Treblle SDK for Flask. Seamlessly integrate Treblle to manage communication with your dashboard, send errors, and secure sensitive data.
https://github.com/treblle/treblle-flask
api api-monitoring api-observability backend developer-tool flask flask-api logging python rest-api restful-api sdk treblle treblle-sdk
Last synced: 2 months ago
JSON representation
The official Treblle SDK for Flask. Seamlessly integrate Treblle to manage communication with your dashboard, send errors, and secure sensitive data.
- Host: GitHub
- URL: https://github.com/treblle/treblle-flask
- Owner: Treblle
- License: mit
- Created: 2023-03-01T15:47:50.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-10T14:42:29.000Z (8 months ago)
- Last Synced: 2024-06-10T16:57:43.044Z (8 months ago)
- Topics: api, api-monitoring, api-observability, backend, developer-tool, flask, flask-api, logging, python, rest-api, restful-api, sdk, treblle, treblle-sdk
- Language: Python
- Homepage: https://www.treblle.com/
- Size: 14.6 KB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# treblle-flask
Treblle makes it super easy to understand what’s going on with your APIs and the apps that use them.
Just by adding Treblle to your API out of the box you get:- Real-time API monitoring and logging
- Auto-generated API docs with OAS support
- API analytics
- Quality scoring
- One-click testing
- API management on the go and more...## Requirements
- python 3.7+
- aiohttp## Basic Usage
You can use Treblle with Flask by importing the Treblle class and passing your Flask app to the constructor,
along with your Treblle API key and project ID.```python
from flask import Flask
from treblle_flask import Treblleapp = Flask(__name__)
Treblle(app, TREBLLE_API_KEY="YOUR_API_KEY", TREBLLE_PROJECT_ID="YOUR_PROJECT_ID")@app.route('/hello')
def hello():
return {"hello": "world"}
```Alternatively, set the following environment variables to configure Treblle without passing any arguments to the
Treblle constructor:- `TREBLLE_API_KEY`: Your Treblle API key
- `TREBLLE_PROJECT_ID`: Your Treblle project IDThat's it! You're all set to start monitoring your API with Treblle.
## Advanced Usage
A number of optional configuration options are available to customize the behavior of Treblle extension:
- `hidden_keys`: A list of keys that should be hidden from the request/response payloads in the Treblle dashboard.
Treblle will automatically hide any keys that contain the strings in this list, or use a default list with common
sensitive keys if this option is not provided.
- `mask_auth_header`: A boolean flag that determines whether the Authorization header should be masked in the Treblle
dashboard. The default value is `True`. Masking the Authorization header will keep the auth type (e.g. Bearer),
visible, but will replace the actual secret with asterisks. If you intend to fo fully hide the header including the
directive, just include it in the `hidden_keys` argument.
- `limit_request_body_size`: The maximum size of the request body that Treblle will attempt to capture. If the request
body exceeds this size, it will be ignored to prevent excessive memory usage. The default value is 4MiB.
- `request_transformer`: A request body transformer function. If passed, this function will receive the original
request body as a bytestring, and should return a JSON-serializable object that will be sent to Treblle. You can use
this function to mask sensitive data in a more customized fashion, remove excess data you don't wish to be logged,
or perform any other transformations you require.
- **Important:** This function will cause the entire request body to be loaded into memory.
- **Important:** Using this function will override the default request body parsing logic - if the request body is a
JSON-encoded string, transformer must return a parsed JSON object, not the string itself.
- `response_transformer`: A response body transformer function. If passed, this function will receive the original
response body as a bytestring, and should return a JSON-serializable object that will be sent to Treblle. You can use
this function to mask sensitive data in a more customized fashion, remove excess data you don't wish to be logged,
or perform any other transformations you require.
- **Important:** This function will not trigger for streaming responses.
- **Important:** Using this function will override the default request body parsing logic - if the response body is a
JSON-encoded string, transformer must return a parsed JSON object, not the string itself.