Skip to main content

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.

Metadata

Release files for arcane-flask 2.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for arcane-flask 2.2.1
File Size Uploaded Provenance Actions
arcane_flask-2.2.1.tar.gz 10.0 kB Without provenance Details for arcane_flask-2.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for arcane-flask 2.2.1
File Interpreter ABI Platform Actions
arcane_flask-2.2.1-py3-none-any.whl Python 3 none any Details for arcane_flask-2.2.1-py3-none-any.whl

Total release size: 21.6 kB

Release files / arcane_flask-2.2.1.tar.gz

Download URL arcane_flask-2.2.1.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1efb63487a6eab115a1dd3d88bf16b26d61f741807bff7b9245748f400214a4d
BLAKE2b-256 checksum
How to use checksums
b1bb732b9bf9836e75ab4d1c59650ae215ad85a2a5571f4812c6b6b344af0dca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.12 Linux/6.11.0-1018-azure

Release files / arcane_flask-2.2.1-py3-none-any.whl

Download URL arcane_flask-2.2.1-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
69163fe161a09a9c0735c48d31edb42735792aa60dd58f8eaac8c57fbb3cefbb
BLAKE2b-256 checksum
How to use checksums
5b9d32364c40c61550d3edd08625f47696b5110b9f24852f27fe95e718891c63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.12 Linux/6.11.0-1018-azure

Security for arcane-flask 2.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.2.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page