A Python package for fetching and converting currency rates using the Prebid currency file.
Project description
Prebid Currency Converter
A Python package for fetching and converting currency rates using the Prebid currency file. The library provides a simple interface to convert amounts between different currencies, with automatic caching of currency data to minimize API requests.
Installation
pip install prepid
Quick Start
from prepid import CurrencyConverter
converter = CurrencyConverter()
# Convert 100 USD to EUR
amount = converter.convert_currency(100, "USD", "EUR")
print(f"100 USD = {amount:.2f} EUR")
Usage
Convert Currency
from prepid import CurrencyConverter, CurrencyError
converter = CurrencyConverter()
try:
result = converter.convert_currency(250, "GBP", "USD")
print(f"250 GBP = {result:.2f} USD")
except CurrencyError as e:
print(f"Conversion failed: {e}")
Currency codes are case-insensitive — "usd", "USD", and " Usd " all work.
Get a Conversion Rate
rate = converter.get_conversion_rate("EUR", "GBP")
print(f"1 EUR = {rate:.4f} GBP")
List Available Currencies
currencies = converter.list_available_currencies()
print(", ".join(currencies)) # AED, ARS, AUD, ...
Caching
The library caches currency data both in-memory and on disk to avoid redundant API calls. By default, data expires after 6 hours:
# Set cache to expire after 24 hours
converter = CurrencyConverter(cache_duration_hours=24)
The disk cache is stored in a platform-appropriate user cache directory.
API Reference
CurrencyConverter(cache_duration_hours=6)
| Method | Returns | Description |
|---|---|---|
convert_currency(amount, from_currency, to_currency) |
float |
Convert an amount between currencies |
get_conversion_rate(from_currency, to_currency) |
float |
Get the rate multiplier between two currencies |
list_available_currencies() |
list[str] |
Sorted list of available currency codes |
get_currency_rates() |
dict |
Raw currency data from the Prebid API |
CurrencyError
Raised when a conversion fails (invalid currency code, network error, etc.).
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.
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 prepid-1.0.0.tar.gz.
File metadata
- Download URL: prepid-1.0.0.tar.gz
- Upload date:
- Size: 23.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aaa71bc9ae7e02c0dedce1153b411e49ffc698fc9defae1d18ddd7b6d9d4cdd5
|
|
| MD5 |
9babf082c5b41d39c51064724cc54814
|
|
| BLAKE2b-256 |
75e2ee7e46c9b9be26cd5178972e532220c1232805d3a4258a4feb78d1ab5924
|
File details
Details for the file prepid-1.0.0-py3-none-any.whl.
File metadata
- Download URL: prepid-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f8fb5751a253d10d2697cf01c69c6819738deb1d7c2f7991a29ca5d544d12e2
|
|
| MD5 |
d486c7487cbb20912ae83dcc8f450cf7
|
|
| BLAKE2b-256 |
1d21415c9962073e973a1ad39c65d2407b3b5be77c5cafaf528e548c25018d2b
|