Apache Airflow provider for UniRateAPI: hooks, operators, and sensors for real-time and historical currency exchange rates.
Project description
airflow-provider-unirate
Apache Airflow provider for UniRateAPI — real-time and historical currency exchange rates. Hook, two operators, and one sensor for plugging FX rates into your DAGs.
Install
pip install airflow-provider-unirate
Requires apache-airflow >= 2.10 (works on 2.10, 2.11, and 3.x).
Connection setup
Create an Airflow connection of type UniRate:
| Field | Value |
|---|---|
| Conn Id | unirate_default (or your own) |
| Conn Type | UniRate |
| API Key | your UniRate key (password field) |
Or via env var:
export AIRFLOW_CONN_UNIRATE_DEFAULT='unirate://:YOUR_API_KEY@'
Get a free key at https://unirateapi.com.
Components
Hook — UniRateHook
from unirate_provider.hooks.unirate import UniRateHook
hook = UniRateHook(unirate_conn_id="unirate_default")
rate = hook.get_rate("USD", "EUR") # latest spot rate
amount = hook.convert("USD", "EUR", 100) # convert 100 USD → EUR
hist = hook.get_historical_rate("2024-01-15", "USD", "EUR") # Pro plan
codes = hook.list_currencies() # ['USD', 'EUR', ...]
Operators
from unirate_provider.operators.unirate import (
UniRateGetRateOperator,
UniRateConvertOperator,
)
latest = UniRateGetRateOperator(
task_id="latest_eur",
from_currency="USD",
to_currency="EUR",
)
# Historical via the same operator (Pro plan; pass YYYY-MM-DD).
historical = UniRateGetRateOperator(
task_id="hist_eur",
from_currency="USD",
to_currency="EUR",
date="{{ ds }}",
)
convert = UniRateConvertOperator(
task_id="convert_invoice",
from_currency="USD",
to_currency="EUR",
amount="{{ ti.xcom_pull(task_ids='upstream', key='amount_usd') }}",
)
Both operators push their result (a float) to XCom. from_currency,
to_currency, amount, and date are all templated.
Sensor — UniRateRateChangeSensor
Trigger downstream work when an FX rate moves beyond a threshold.
from unirate_provider.sensors.unirate import UniRateRateChangeSensor
# Wake up downstream tasks when EUR moves >1% from a fixed reference.
big_move = UniRateRateChangeSensor(
task_id="watch_eur",
from_currency="USD",
to_currency="EUR",
threshold_pct=0.01, # 1%
baseline_rate=0.92, # if omitted, the first poke sets the baseline
direction="any", # 'any' | 'up' | 'down'
poke_interval=3600, # check hourly
mode="reschedule", # default; releases the worker slot between pokes
timeout=60 * 60 * 24, # give up after 24h
)
The crossing rate is pushed to XCom on success.
Example DAG
A complete example lives at unirate_provider/example_dags/example_unirate.py.
Testing
pip install -e ".[test]"
pytest
Status
v0.1.0 — initial release. Hook + 2 operators + 1 sensor. 30 unit tests.
License
MIT. UniRate client (unirate-api) is also MIT.
Links
- UniRate API docs: https://unirateapi.com/docs
- Airflow custom-providers howto: https://airflow.apache.org/docs/apache-airflow-providers/howto/create-custom-providers.html
- Issues: https://github.com/UniRate-API/airflow-provider-unirate/issues
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 airflow_provider_unirate-0.1.0.tar.gz.
File metadata
- Download URL: airflow_provider_unirate-0.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf66b268ed3de1dcd1b82ff8ed2a13c7e1c220fe57f048729a7372257b92efe7
|
|
| MD5 |
b5b37c7e4af536b3e8e0a0e1d80dad98
|
|
| BLAKE2b-256 |
d77c5160e1fb09c30a820e88474687ab127f6c59a89293e9311e8f4241ae8edb
|
Provenance
The following attestation bundles were made for airflow_provider_unirate-0.1.0.tar.gz:
Publisher:
release.yml on UniRate-API/airflow-provider-unirate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
airflow_provider_unirate-0.1.0.tar.gz -
Subject digest:
cf66b268ed3de1dcd1b82ff8ed2a13c7e1c220fe57f048729a7372257b92efe7 - Sigstore transparency entry: 1436953230
- Sigstore integration time:
-
Permalink:
UniRate-API/airflow-provider-unirate@c61ae78fdc463e977484a62a2928fb3ad8227a01 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/UniRate-API
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c61ae78fdc463e977484a62a2928fb3ad8227a01 -
Trigger Event:
push
-
Statement type:
File details
Details for the file airflow_provider_unirate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: airflow_provider_unirate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ab36f6791ed134ea57844566da908e18495213d487b722829f6c065ee9c5318
|
|
| MD5 |
b44cfdc2dd33a83d63ceaed7074bc0ef
|
|
| BLAKE2b-256 |
65b6165249f77fca2c4e7fcb853a46c1397d7bc197582ccfc7bbe5e547615bec
|
Provenance
The following attestation bundles were made for airflow_provider_unirate-0.1.0-py3-none-any.whl:
Publisher:
release.yml on UniRate-API/airflow-provider-unirate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
airflow_provider_unirate-0.1.0-py3-none-any.whl -
Subject digest:
9ab36f6791ed134ea57844566da908e18495213d487b722829f6c065ee9c5318 - Sigstore transparency entry: 1436953242
- Sigstore integration time:
-
Permalink:
UniRate-API/airflow-provider-unirate@c61ae78fdc463e977484a62a2928fb3ad8227a01 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/UniRate-API
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c61ae78fdc463e977484a62a2928fb3ad8227a01 -
Trigger Event:
push
-
Statement type: