Utility functions for flask apps.
Project description
Arcane flask
This package help us authenticate users
Get Started
pip install arcane-flask
Example Usage
from arcane.flask import check_access_rights
from arcane.core import RightsLevelEnum, UserRightsEnum
from arcane.datastore import Client as DatastoreClient
from arcane.pubsub import Client as PubSubClient
datastore_client = DatastoreClient()
pubsub_client = PubSubClient()
@check_access_rights(
service='my-service',
required_rights=RightsLevelEnum.VIEWER,
service_user_right=UserRightsEnum.MY_SERVICE,
datastore_client=datastore_client,
pubsub_client=pubsub_client,
receive_rights_per_client=True,
project='my-project',
timeout=30 # Timeout in seconds
)
def function(params):
pass
Timeout Configuration
The check_access_rights decorator includes a built-in timeout parameter that allows you to set a maximum execution time for the decorated function. If the function exceeds this timeout, the decorator will automatically return a timeout response.
import time
@check_access_rights(
service='my-service',
required_rights=RightsLevelEnum.VIEWER,
service_user_right=UserRightsEnum.MY_SERVICE,
datastore_client=datastore_client,
pubsub_client=pubsub_client,
project='my-project',
timeout=2 # 2 seconds timeout
)
def slow_function():
time.sleep(5) # This will exceed the timeout
return {'result': 'success'}
If the function exceeds the timeout, the decorator will return:
({'detail': 'Request Timeout'}, 504)
Note: Set the timeout parameter to a value a few seconds less than your Cloud Run or server timeout configuration to ensure proper error handling.
Structured logging labels
The arcane.flask.logs module lets you add structured labels to every log
entry in a request. This is useful for attaching metadata such as
component, module, function, or IDs like optimization_id.
First, set up logging once at application startup:
from arcane.flask import logs
logs.setup_logging(gcp_project="my-gcp-project-id")
Then, register a teardown handler to clear labels at the end of each request:
from arcane.flask import logs
@app.teardown_request
def clear_logging_labels(exc):
logs.clear_labels()
Inside your handlers you can either attach labels imperatively:
from arcane.flask import logs
def validate_model_parallelism_post(optimization_id: str, job_prefix: str, ...):
logs.attach_labels(
component="feed-boost",
module="api",
function="validate_model_parallelism_post",
optimization_id=optimization_id,
job_prefix=job_prefix,
)
...
or use the with_log_labels decorator for static labels and still add dynamic
labels as needed:
from arcane.flask import logs
@logs.with_log_labels(
component="feed-boost",
module="api",
function="validate_model_parallelism_post",
)
def validate_model_parallelism_post(optimization_id: str, job_prefix: str, ...):
logs.attach_labels(
optimization_id=optimization_id,
job_prefix=job_prefix,
)
...
All log records emitted during the request will then include a
logging.googleapis.com/labels field with the JSON-encoded labels.
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 arcane_flask-3.0.0.tar.gz.
File metadata
- Download URL: arcane_flask-3.0.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.12 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
040bb92d8159430e283bd04d6187e73a1c523197fefad5fbfeef4b5034543ccc
|
|
| MD5 |
cd92ff57d5efa37c9457958750a492e1
|
|
| BLAKE2b-256 |
6220f7e5a0d9bbff329b073bcd2a29688711e36a54ac88b4f655d01d4fc6c429
|
File details
Details for the file arcane_flask-3.0.0-py3-none-any.whl.
File metadata
- Download URL: arcane_flask-3.0.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.12 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f900a0bad38413be2a454a6fc50ba0f8738fe2b68120a3d19f13e86855216ad4
|
|
| MD5 |
a673133bd35515ccc64bca3e13e7ea77
|
|
| BLAKE2b-256 |
88166bc69851f8cca392d7ad3903c8dae13b9b80c569fb09b1033c6a5f7e7fe0
|