Skip to main content

osn-currencies-tools: A Python Library for Currency Exchange

osn-currencies-tools provides a set of tools for fetching and converting currency exchange rates. It includes functionalities to retrieve live exchange rates from currencylive.com and exchangerate-api.com, as well as via the Open Exchange Rates API. The library handles currency conversion and provides exception handling for invalid currency codes and failed API requests.

Key Features:

  • Multiple Exchange Rate Sources: Supports fetching exchange rates from currencylive.com, exchangerate-api.com, and Open Exchange Rates API.
  • Currency Conversion: Allows easy conversion between different currencies.
  • Error Handling: Provides custom exceptions for handling invalid currency codes and API errors.
  • Currency Tag Validation: Validates currency tags against a predefined list.
  • Simple API: Offers a clean and intuitive API for currency exchange operations.

Installation:

  • With pip:

    pip install osn-currencies-tools
    
  • With git:

    pip install git+https://github.com/oddshellnick/osn-currencies-tools.git
    

API Reference:

  • currency_live: Fetches live exchange rates from currencylive.com.

    • get_exchange_rate(from_currency_tag: str, to_currency_tag: str) -> float: Retrieves the exchange rate between two currencies.
    • exchange_currency(currency_amount: float, from_currency_tag: str, to_currency_tag: str) -> float: Converts an amount from one currency to another.
  • exchange_rate: Fetches exchange rates from exchangerate-api.com.

    • get_exchange_rate(api_key: str, from_currency_tag: str, to_currency_tag: str) -> float: Retrieves the exchange rate between two currencies.
    • exchange_currency(api_key: str, currency_amount: float, from_currency_tag: str, to_currency_tag: str) -> float: Converts an amount from one currency to another.
  • open_exchange_rates: Fetches exchange rates from Open Exchange Rates API.

    • get_exchange_rate(app_id: str, from_currency_tag: str, to_currency_tag: str) -> float: Retrieves the exchange rate between two currencies.
    • exchange_currency(app_id: str, currency_amount: float, from_currency_tag: str, to_currency_tag: str) -> float: Converts an amount from one currency to another.
  • data: Contains currency tags and symbols.

    • CurrenciesTags: A dataclass containing currency abbreviations for all countries.
    • CurrenciesSymbols: A dataclass containing currency symbols for all countries.
    • tag_to_symbol: A dictionary mapping currency tags to symbols.
  • errors: Defines custom exception classes.

    • ExchangeRateNotFoundError: Raised when an exchange rate is not found.
    • CurrencyTagNotFoundError: Raised when a currency abbreviation is not found.

Usage Examples:

Using currencylive.com:

from osn_currencies_tools.currency_live import get_exchange_rate, exchange_currency

try:
    rate = get_exchange_rate("USD", "EUR")
    print(f"Exchange rate USD to EUR: {rate}")

    converted_amount = exchange_currency(100, "USD", "EUR")
    print(f"100 USD in EUR: {converted_amount}")
except Exception as e:
    print(f"An error occurred: {e}")

Using exchangerate-api.com:

from osn_currencies_tools.exchange_rate import get_exchange_rate, exchange_currency

api_key = "YOUR_API_KEY"  # Replace with your actual API key

try:
    rate = get_exchange_rate(api_key, "USD", "EUR")
    print(f"Exchange rate USD to EUR: {rate}")

    converted_amount = exchange_currency(api_key, 100, "USD", "EUR")
    print(f"100 USD in EUR: {converted_amount}")
except Exception as e:
    print(f"An error occurred: {e}")

Using Open Exchange Rates API:

from osn_currencies_tools.open_exchange_rates import get_exchange_rate, exchange_currency

app_id = "YOUR_APP_ID"  # Replace with your actual App ID

try:
    rate = get_exchange_rate(app_id, "USD", "EUR")
    print(f"Exchange rate USD to EUR: {rate}")

    converted_amount = exchange_currency(app_id, 100, "USD", "EUR")
    print(f"100 USD in EUR: {converted_amount}")
except Exception as e:
    print(f"An error occurred: {e}")

Future Notes:

osn-currencies-tools is under active development. Planned future enhancements include support for more exchange rate APIs and caching of exchange rates to reduce API calls. Contributions and suggestions for new features are welcome! Feel free to open issues or submit pull requests on the project's repository.

Release files for osn-currencies-tools 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for osn-currencies-tools 1.0.0
File Size Uploaded
osn_currencies_tools-1.0.0.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for osn-currencies-tools 1.0.0
File Interpreter ABI Platform
osn_currencies_tools-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / osn_currencies_tools-1.0.0.tar.gz

Download URL osn_currencies_tools-1.0.0.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dd705acf6a8c0cf6a373d154e81129e9c196c262bfff38a91e05193280eadd58
BLAKE2b-256 checksum
How to use checksums
3035d4416fe5b9b00b09e71b830ace6739374ed062986de35c07cda4d5d852b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 9, 2025.

Transparency log

Release files / osn_currencies_tools-1.0.0-py3-none-any.whl

Download URL osn_currencies_tools-1.0.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ffa490591565796733d787d561610e66634dce92d74cd935b25c2af3445f891
BLAKE2b-256 checksum
How to use checksums
5fcc50508cb001211f43fca8200945e0bb5a2a50c97ca3322143fe2796b1af78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 9, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page