Skip to main content

bluecore-airflow-common

Shared helpers, base template and styles for Blue Core Airflow 3 plugins.

Install

uv add bluecore-airflow-common

Usage

from fastapi import Depends, FastAPI, Request

import bluecore_airflow_common as common

URL_PREFIX = "/my-plugin"

app = FastAPI()
common.mount_static(app, "static")
templates = common.templates("templates")


@app.get("/", dependencies=[Depends(common.requires_login)])
def index(request: Request):
    return templates.TemplateResponse(
        request, "index.html", common.context(URL_PREFIX, title="My Plugin")
    )

Plugin pages extend the shared base template:

{% extends "bluecore/base.html" %}
{% block content %}<h1>{{ title }}</h1>{% endblock %}

Shared assets are served at {url_prefix}/static/bluecore/, and a plugin's own files at {url_prefix}/static/. In tests, switch off authentication with app.dependency_overrides[common.requires_login] = lambda: None.

PyScript

Pages that run PyScript include the shared tags, which pin one release with Subresource Integrity:

{% block head %}{% include "bluecore/_pyscript.html" %}{% endblock %}

To move to a new release, run uv run python scripts/pyscript_sri.py <version>. The Content-Security-Policy these pages need is in docs/integration-contracts.md.

Integration

bluecore_airflow_common.integration builds clients for the Blue Core API (bluecore-client) and Airflow's /api/v2 (apache-airflow-client), and reads reports and stages uploads on the shared volumes. import bluecore_airflow_common doesn't load it, so plugins that only use the templates don't need its configuration. What each upstream capability offers, and what's still missing, is in docs/integration-contracts.md.

Configuration

Read from the environment, which bluecore-stack sets from .env:

Variable
BLUECORE_API_INTERNAL_URL required. The Blue Core API as the Airflow containers reach it, e.g. http://bc_api:8100
BLUECORE_URL required. The Blue Core site as the browser reaches it, e.g. https://bcld.info
AIRFLOW_API_INTERNAL_URL required. Airflow as the plugins reach it, e.g. http://airflow-apiserver:8080/workflows
BLUECORE_REQUEST_TIMEOUT seconds per upstream request, default 10
BLUECORE_MAX_RETRIES retries for GET and HEAD, default 2, at most 5
BLUECORE_REPORTS_DIR the reports volume, default /opt/airflow/reports
BLUECORE_UPLOADS_DIR the uploads volume, default /opt/airflow/uploads

Missing settings are logged when the module is imported, and raise SettingsError when first used. public_config() returns the only settings that are safe to send to a browser.

Usage

from typing import Annotated

from airflow_client.client import DagRunApi
from fastapi import Depends, FastAPI

from bluecore_airflow_common.integration import airflow, auth, blue_core
from bluecore_airflow_common.integration.errors import install_error_handler
from bluecore_airflow_common.integration.settings import BlueCoreSettings, get_settings

USER_AGENT = "my-plugin/1.0.0"

app = FastAPI()
install_error_handler(app)
auth.install_token_redaction()

Settings = Annotated[BlueCoreSettings, Depends(get_settings)]


@app.get("/works/{uuid}")
def work(uuid: str, settings: Settings) -> dict:
    with blue_core.make_client(settings, user_agent=USER_AGENT) as client:
        return client.works.get(uuid)


@app.get("/jobs/{run_id}")
def job(run_id: str, settings: Settings, token: auth.AirflowToken) -> dict:
    api_client = airflow.make_client(settings, token=token, user_agent=USER_AGENT)
    run = DagRunApi(api_client).get_dag_run(
        "marc_to_bibframe", run_id, _request_timeout=settings.request_timeout
    )
    return {"state": run.state}

Use plain def routes: both clients are synchronous, so FastAPI runs them in its threadpool. Reads from Blue Core are anonymous; for a write, pass token= from auth.KeycloakToken to blue_core.make_client. Upstream failures come back as {"error": {"code", "message", "upstream_status", "request_id"}}.

Testing

Override the settings and tokens with FastAPI's dependency overrides, and mock the HTTP layer underneath the clients:

from bluecore_airflow_common.integration import auth
from bluecore_airflow_common.integration.settings import BlueCoreSettings, get_settings

app.dependency_overrides[get_settings] = lambda: BlueCoreSettings(
    internal_url="http://bluecore.test",
    public_url="https://bluecore.test",
    airflow_internal_url="http://airflow.test",
)
app.dependency_overrides[auth.airflow_token] = lambda: "test-token"
app.dependency_overrides[auth.keycloak_token] = lambda: "test-token"
  • Blue Core: mock http://bluecore.test with respx, since bluecore-client uses httpx.
  • Airflow: patch the API class your route calls, such as DagRunApi.get_dag_run, or point airflow_internal_url at a local server.
  • Tests that read the environment instead should call get_settings.cache_clear() after changing it.
  • Point BLUECORE_REPORTS_DIR and BLUECORE_UPLOADS_DIR at tmp_path, or pass base_dir= to reports.run_dir and uploads.stage_upload.

Development

uv run ruff format && uv run ruff check
uv run ty check
uv run pytest

Metadata

Release files for bluecore-airflow-common 0.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 bluecore-airflow-common 0.2.1
File Size Uploaded Provenance Actions
bluecore_airflow_common-0.2.1.tar.gz 19.8 kB With provenance Details for bluecore_airflow_common-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bluecore-airflow-common 0.2.1
File Interpreter ABI Platform Actions
bluecore_airflow_common-0.2.1-py3-none-any.whl Python 3 none any Details for bluecore_airflow_common-0.2.1-py3-none-any.whl

Total release size: 45.4 kB

Release files / bluecore_airflow_common-0.2.1.tar.gz

Download URL bluecore_airflow_common-0.2.1.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fe4a5c3977d0929392170480be76ab837def1af35e89f1d6019618b3b13c539c
BLAKE2b-256 checksum
How to use checksums
e3e2fcf00cc6fa307a6750c86c6c6969733b3ef122960652ac28af5b9b1d55b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / bluecore_airflow_common-0.2.1-py3-none-any.whl

Download URL bluecore_airflow_common-0.2.1-py3-none-any.whl
Size 25.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd7d0a0e6f9f9403aaa3f839f6dd2df29e9a4b507c53010777c9097221caf751
BLAKE2b-256 checksum
How to use checksums
c0ae76be38c77f37eaa14b7965989d154d216347e4d98cb3467ac2649f79a836
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for bluecore-airflow-common 0.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bluecore_airflow_common-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

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.

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