No project description provided
Project description
Flytrap Flask SDK
The Flytrap Flask SDK is a lightweight tool designed for Flask applications. It enables seamless error monitoring and reporting to the Flytrap system, capturing both global and manually handled errors with minimal setup.
This guide will walk you through setting up the Flytrap Flask SDK in your project and exploring its features. If you want to use Flytrap in a production environment, refer to the Flytrap Installation Guide for complete setup instructions.
To learn more about Flytrap, check out our case study.
🚀 Getting Started
To start using Flytrap in your project:
- Visit the Flytrap Dashboard and log in.
- Click on New Project to create a project.
- You’ll be provided with a Project ID, API Key, and API Endpoint specific to your project. These values are essential for configuring the SDK.
📦 Installation
Install the Flytrap Flask SDK via pip:
pip install flytrap_flask
🛠️ Usage
-
Initialize Flytrap: In your main application file (e.g., app.py), import the Flytrap module and initialize it with your project credentials:
import flytrap flytrap.init({ "project_id": "YOUR_PROJECT_ID", # Replace with your Project ID "api_endpoint": "YOUR_ENDPOINT", # Replace with your API Endpoint "api_key": "YOUR_API_KEY", # Replace with your API Key })
-
Automatically Capture Global Errors: The Flytrap Flask SDK sets up a
sys.excepthookto automatically log uncaught exceptions globally, even outside Flask request cycles. This ensures all unhandled errors are captured and sent to Flytrap without additional configuration. -
Set Up Flask Middleware: Add the Flytrap error handler to your Flask app to automatically capture unhandled errors:
from flask import Flask import flytrap app = Flask(__name__) flytrap.setup_flask_error_handler(app)
This middleware intercepts any unhandled errors in your Flask routes and logs them to Flytrap, along with request metadata (e.g., HTTP method and path).
-
Manually Capturing Exceptions: For exceptions caught in a try/except block, use the capture_exception method to log the error to Flytrap manually:
try: # Your code here raise Exception("Something went wrong!") except Exception as e: flytrap.capture_exception(e)
🛠️ Example App Setup
Here’s a complete example of using Flytrap in a Flask application:
from flask import Flask
import flytrap
app = Flask(__name__)
# Initialize the Flytrap SDK
flytrap.init({
"project_id": "YOUR_PROJECT_ID",
"api_endpoint": "YOUR_ENDPOINT",
"api_key": "YOUR_API_KEY"
})
# Set up Flytrap middleware
flytrap.setup_flask_error_handler(app)
@app.route("/")
def home():
return "Hello, World!"
@app.route("/unhandled-error")
def unhandled_error():
raise Exception("Unhandled error in route")
@app.route("/handled-error")
def handled_error():
try:
raise Exception("Handled error in route")
except Exception as e:
flytrap.capture_exception(e)
return "Handled error logged", 400
if __name__ == "__main__":
app.run(debug=True, port=3003)
🖥️ Local End-to-End Testing with Flytrap Architecture
For full local integration with the Flytrap architecture:
- Install the Flytrap API: Follow the Flytrap API Repository setup guide.
- Install the Flytrap Processor: Refer to the Flytrap Processor Repository for instructions.
- View Errors in the Dashboard: Set up the Flytrap Dashboard to view and manage reported errors.
- Integrate the Flytrap SDK in your project.
Testing the Complete Setup
- Trigger errors in your application integrated with a Flytrap SDK.
- Confirm that errors are logged by checking:
- Flytrap Processor Logs: Ensure errors are processed correctly.
- Flytrap Dashboard: View processed errors, including stack traces and context.
🚀 Production Setup
If you’re looking for detailed instructions to deploy Flytrap in a production environment, refer to:
For questions or issues, feel free to open an issue in this repository or contact the Flytrap team. 🚀
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flytrap_flask-0.1.1.tar.gz.
File metadata
- Download URL: flytrap_flask-0.1.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5830c9fd748914a5ead7ac5095a94e3d0793eb5e88f1771ced97780b78be42dd
|
|
| MD5 |
978f59eac90c3aca86b6a51391f7d6d9
|
|
| BLAKE2b-256 |
e643af32524716dfc82675169dd65999e08eeec3c22fbfac838569aac8466d6b
|
File details
Details for the file flytrap_flask-0.1.1-py3-none-any.whl.
File metadata
- Download URL: flytrap_flask-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86e947421b38e63b12c6ee475ee4fb63d5f5e670083cc8768f18daca534e61cb
|
|
| MD5 |
93d29be8b6d261ccf8b3d45aa3c5be01
|
|
| BLAKE2b-256 |
aa64a500df8748cb59ccb431ca87fa31a35cc55f4ff4780056e84086b48ec919
|