litestar-unirate
Litestar plugin for the UniRate currency-exchange API:
UniRatePlugin— anInitPluginProtocolplugin that provides a shared, asyncUniRateClientto your handlers through Litestar's dependency injection (injected asunirateby default).- Prebuilt route handlers — a
UniRateControllermounted at/unirateexposingGET /unirate/rate,/convert,/currencies, and/vat, with full UniRate error mapping onto Litestar HTTP exceptions. - One HTTP client per app — an
httpx.AsyncClient-backed client opened on demand and closed on shutdown.
UniRate covers 593+ fiat, crypto, and commodity codes. Latest rates,
conversion, currencies, and VAT are on the free tier; historical endpoints
(convert_historical) require Pro.
Install
pip install litestar-unirate
Or with uv / Poetry:
uv add litestar-unirate
poetry add litestar-unirate
Quick start
from litestar import Litestar, get
from litestar_unirate import UniRateClient, UniRateConfig, UniRatePlugin
app = Litestar(
plugins=[UniRatePlugin(UniRateConfig())], # reads UNIRATE_API_KEY from env
)
That alone mounts the prebuilt endpoints:
$ curl 'localhost:8000/unirate/rate?from_currency=USD&to_currency=JPY'
{"rate":151.83}
$ curl 'localhost:8000/unirate/convert?from_currency=USD&to_currency=EUR&amount=100'
{"result":92.5}
$ curl localhost:8000/unirate/currencies
{"currencies":["USD","EUR","GBP", ...]}
$ curl 'localhost:8000/unirate/vat?country=DE'
{"country":"DE","vat_data":{"country_code":"DE","country_name":"Germany","vat_rate":19.0}}
The plugin also injects the client into your own handlers under the unirate
key:
@get("/summary")
async def summary(unirate: UniRateClient) -> dict[str, object]:
return {"usd_eur": await unirate.get_rate("USD", "EUR")}
Configuration
UniRateConfig controls the client and the routes:
UniRateConfig(
api_key=None, # default: $UNIRATE_API_KEY
base_url="https://api.unirateapi.com", # default: production
timeout=30.0, # HTTP timeout (seconds)
dependency_key="unirate", # DI name for the client
register_routes=True, # mount the prebuilt /unirate/* routes
route_path_prefix="/unirate", # where to mount them
)
Set register_routes=False to expose only the injectable client and wire your
own handlers.
Note: the prebuilt
UniRateControllerinjects the client under the nameunirate. If you set a customdependency_key, keepregister_routes=False(or use the default key) so the controller resolves its dependency.
Client methods
The injected UniRateClient is a small async wrapper over UniRate:
| Method | Returns |
|---|---|
get_rate(from_currency="USD", to_currency=None) |
float for a pair, else dict[str, float] |
convert(from_currency, to_currency, amount=1.0) |
float |
get_supported_currencies() |
list[str] |
get_vat_rates(country=None) |
dict (vat_rates map, or vat_data for one country) |
convert_historical(from_currency, to_currency, date, amount=1.0) |
float (Pro) |
Errors
The client raises UniRateAPIError (with status_code) on non-2xx responses.
The prebuilt handlers translate those onto Litestar HTTP exceptions:
| UniRate HTTP | Litestar exception | Response |
|---|---|---|
| 400 | ClientException |
400 |
| 401 | NotAuthorizedException |
401 |
| 403 | PermissionDeniedException |
403 (Pro required) |
| 404 | NotFoundException |
404 |
| 429 | TooManyRequestsException |
429 |
| 503 | ServiceUnavailableException |
503 |
| transport / other | HTTPException |
502 |
Compatibility
- Python 3.10 – 3.13
- Litestar ≥ 2.0
- httpx ≥ 0.27
Related
unirate-api— sync UniRate Python client.fastapi-unirate— FastAPI integration.flask-unirate— Flask integration.- Other UniRate integrations: dbt, Airflow, LangChain, MCP server. Full list at https://unirateapi.com.
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.
- Languages: Python · Node.js / TypeScript · Go · Rust · Java · Ruby · PHP · .NET · Swift
- Web frameworks: FastAPI · Flask · NestJS · Django / Wagtail · React · tRPC
- Static-site generators: Astro · Eleventy · Hugo
- Data / orchestration: Airflow · dbt · LangChain
- Workflow / no-code: n8n · Google Sheets · MCP server
Get a free API key at unirateapi.com.
License
MIT
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 litestar_unirate-0.1.0.tar.gz.
File metadata
- Download URL: litestar_unirate-0.1.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83594bf2147ecea29029c10e63cba13d81e569ea698216616d99b599ef6deecd
|
|
| MD5 |
5c108ea27304bf065efeca3945888be9
|
|
| BLAKE2b-256 |
6baaaaa19ca5117ff930f84b32bb8a5d580495360bc0399a389d7a2886a675e9
|
Provenance
The following attestation bundles were made for litestar_unirate-0.1.0.tar.gz:
Publisher:
release.yml on UniRate-API/litestar-unirate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_unirate-0.1.0.tar.gz -
Subject digest:
83594bf2147ecea29029c10e63cba13d81e569ea698216616d99b599ef6deecd - Sigstore transparency entry: 2497604539
- Sigstore integration time:
-
Permalink:
UniRate-API/litestar-unirate@7a98e3b06efc457b576c94eb78bdaa53ad942a49 -
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@7a98e3b06efc457b576c94eb78bdaa53ad942a49 -
Trigger Event:
push
-
Statement type:
File details
Details for the file litestar_unirate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: litestar_unirate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
369ca16bdabfbe790493f440722a115b15f5e98a0d1b1e55230ca52b622c92af
|
|
| MD5 |
56e5b08551a86b0b8cf557c0f997e711
|
|
| BLAKE2b-256 |
9c743536fd3141f1507fb5b09e9b2d63f4ce591ac72ce1788a7348c4284d92e6
|
Provenance
The following attestation bundles were made for litestar_unirate-0.1.0-py3-none-any.whl:
Publisher:
release.yml on UniRate-API/litestar-unirate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_unirate-0.1.0-py3-none-any.whl -
Subject digest:
369ca16bdabfbe790493f440722a115b15f5e98a0d1b1e55230ca52b622c92af - Sigstore transparency entry: 2497604632
- Sigstore integration time:
-
Permalink:
UniRate-API/litestar-unirate@7a98e3b06efc457b576c94eb78bdaa53ad942a49 -
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@7a98e3b06efc457b576c94eb78bdaa53ad942a49 -
Trigger Event:
push
-
Statement type: