Skip to main content

osn-currencies-tools is a Python library for easy currency conversion and information retrieval, providing real-time exchange rates and a comprehensive list of currency symbols and tags.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

osn_currencies_tools-1.0.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

osn_currencies_tools-1.0.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file osn_currencies_tools-1.0.0.tar.gz.

File metadata

  • Download URL: osn_currencies_tools-1.0.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for osn_currencies_tools-1.0.0.tar.gz
Algorithm Hash digest
SHA256 dd705acf6a8c0cf6a373d154e81129e9c196c262bfff38a91e05193280eadd58
MD5 edbc8378ab197568c3220d535e6a851d
BLAKE2b-256 3035d4416fe5b9b00b09e71b830ace6739374ed062986de35c07cda4d5d852b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for osn_currencies_tools-1.0.0.tar.gz:

Publisher: python-publish.yml on oddshellnick/osn-currencies-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file osn_currencies_tools-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for osn_currencies_tools-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ffa490591565796733d787d561610e66634dce92d74cd935b25c2af3445f891
MD5 451d005aea261651abca3d7f963a339e
BLAKE2b-256 5fcc50508cb001211f43fca8200945e0bb5a2a50c97ca3322143fe2796b1af78

See more details on using hashes here.

Provenance

The following attestation bundles were made for osn_currencies_tools-1.0.0-py3-none-any.whl:

Publisher: python-publish.yml on oddshellnick/osn-currencies-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page