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
You can install the package from PyPI:
pip install prepid
Usage
Here's a quick example of how to use the CurrencyConverter to convert 100 USD to EUR:
from prepid import CurrencyConverter
# Initialize the converter
converter = CurrencyConverter()
# Convert 100 USD to EUR
try:
converted_amount = converter.convert_currency(100, 'USD', 'EUR')
print(f"100 USD is equal to {converted_amount:.2f} EUR")
except (ValueError, Exception) as e:
print(f"Error: {e}")
# List all available currencies
try:
available_currencies = converter.list_available_currencies()
print("\nAvailable currencies:")
print(', '.join(available_currencies))
except Exception as e:
print(f"Error fetching currency list: {e}")
Caching
The library automatically caches the currency data to avoid fetching it from the API on every request. By default, the cache expires after 6 hours. You can configure the cache duration when you initialize the CurrencyConverter:
# Set cache to expire after 24 hours
converter = CurrencyConverter(cache_duration_hours=24)
The cache is stored in a user-specific directory, so it won't clutter your project folder.
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-0.0.1.tar.gz.
File metadata
- Download URL: prepid-0.0.1.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1839b8ac8a306554aafe2a1bc2e94bd94f60029f4bb680e35dae7ef9add88a8c
|
|
| MD5 |
7be6cdc9f00eda2c2c9f7da5e03e1b37
|
|
| BLAKE2b-256 |
43998a708df8dc6cd5596db684dce9b81ec29e32780616a04a5eb052aec36e66
|
File details
Details for the file prepid-0.0.1-py3-none-any.whl.
File metadata
- Download URL: prepid-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc2da2d7976357cc2ae8e8bcec7bf07d15ce76e1ffd90d1cb3b2975de16d33a6
|
|
| MD5 |
e5ea7ce042d75dda72e26c08d00a834d
|
|
| BLAKE2b-256 |
8040c5074d698043334a9305ea03e4e8b45e135c914675937c8e425564a6f628
|