Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

prefect-unirate

PyPI Prefect License

Prefect 3 integration for UniRateAPI — real-time currency exchange rates, conversion, currency lists, and VAT rates as first-class Prefect tasks, wired up through a reusable credentials block.

Install

pip install prefect-unirate

Requires prefect >= 3.0.0 and Python 3.10+. Get a free API key at https://unirateapi.com.

Credentials

UniRateCredentials is a Prefect Block that stores your API key (as a SecretStr) and builds a client.

Register the block type once, then save an instance you can reuse across flows:

prefect block register -m prefect_unirate
from prefect_unirate import UniRateCredentials

UniRateCredentials(api_key="your-key").save("unirate")

Load it anywhere with UniRateCredentials.load("unirate").

Tasks

from prefect import flow
from prefect_unirate import (
    UniRateCredentials,
    get_exchange_rate,
    convert_currency,
    list_currencies,
    get_vat_rates,
)


@flow
def fx() -> None:
    creds = UniRateCredentials.load("unirate")

    rate = get_exchange_rate(creds, "USD", "EUR")     # 0.92
    amount = convert_currency(creds, "EUR", 100, "USD")  # 92.5
    codes = list_currencies(creds)                    # ['USD', 'EUR', ...]
    vat = get_vat_rates(creds, "DE")                  # {'country': 'DE', ...}
Task Endpoint Returns
get_exchange_rate(creds, from_currency="USD", to_currency=None) /api/rates float, or {code: rate} when to_currency is omitted
convert_currency(creds, to_currency, amount=1, from_currency="USD") /api/convert float, or {code: amount}
list_currencies(creds) /api/currencies list[str]
get_vat_rates(creds, country=None) /api/vat/rates dict

Currency and country codes are uppercased automatically before being sent.

Error handling

Every task raises a typed exception on failure (all subclass UnirateError):

Status Exception
400 InvalidDateError
401 AuthenticationError
403 APIError (status_code=403) — endpoint requires a Pro subscription
404 InvalidCurrencyError
429 RateLimitError
503 APIError (status_code=503)
network/transport UnirateError

Historical endpoints are Pro-gated and return 403 on the free tier.

Example flow

A complete runnable flow lives at examples/example_flow.py. It reads UNIRATE_API_KEY from the environment.

Testing

pip install -e ".[test]"
pytest

Tests run against a temporary Prefect database via prefect_test_harness, with the HTTP layer mocked by respx — no network access and no real Prefect server.

Status

v0.1.0 — initial release. Credentials block + 4 tasks. 30+ mock tests.

Other UniRate clients

UniRate ships official client libraries and framework integrations across the ecosystem. The repos below are all maintained under the UniRate-API org.

Get a free API key at unirateapi.com.

License

MIT.

Links

About

Prefect 3 integration for the UniRate currency-exchange API — credentials block + tasks for rates, conversion, currencies, and VAT.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages