Skip to main content

A robust and free currency converter module for Python, supporting multiple sources like ECB and CBR.

Project description

Currency Converter Free

Currency Converter Free is a Python library designed for seamless and efficient currency conversion, leveraging exchange rates from two trusted sources: the Central Bank of Russia (CBR) and the European Central Bank (ECB). With its robust caching and flexibility, this library is ideal for financial applications requiring reliable currency data.

Key Features

  • Multiple Data Sources: Fetch exchange rates from CBR, ECB, or combine both for comprehensive currency coverage.
  • Disk-Based Caching: Persistent caching reduces API calls and boosts performance.
  • Automatic Base Currency Management: Transparently handles base currency differences (RUB for CBR and EUR for ECB).
  • Flexible Conversion: Convert between any two supported currencies with ease.
  • Customizable: Easily configurable to adjust caching behavior, data sources, or apply currency-specific correction factors.
  • Optimized for Performance: Uses efficient caching and data handling techniques.

Installation

Install the library via pip:

pip install currency-converter-free

Requirements

If the library is installed manually, ensure dependencies are met:

pip install requests diskcache

Usage

Basic Example

from currency_converter_free import CurrencyConverter

# Initialize the converter
converter = CurrencyConverter()

# Convert 100 USD to EUR
usd_to_eur = converter.convert(100, 'USD', 'EUR')
print(f"100 USD = {usd_to_eur:.2f} EUR")

# Convert 100 RUB to USD
rub_to_usd = converter.convert(100, 'RUB', 'USD')
print(f"100 RUB = {rub_to_usd:.2f} USD")

# List available currencies
currencies = converter.available_currencies()
print("Supported currencies:", currencies)

Advanced Example

Specify Data Source

Choose between CBR, ECB, or both sources for exchange rates:

from currency_converter_free import CurrencyConverter

# Use CBR rates only
converter_cbr = CurrencyConverter(source="CBR")

# Use ECB rates only
converter_ecb = CurrencyConverter(source="ECB")

# Use both CBR and ECB rates
converter_combined = CurrencyConverter(source="BOTH")

Customize Cache Directory

To persist cache in a specific location:

from currency_converter_free import CurrencyConverter

# Specify a custom cache directory
converter = CurrencyConverter(cache_dir="/custom/cache/directory")

Supported Sources

  • CBR (Central Bank of Russia): Provides rates with RUB as the base currency.
  • ECB (European Central Bank): Offers rates with EUR as the base currency.

When using the "BOTH" source, the library intelligently combines rates from CBR and ECB, prioritizing accuracy for RUB-based and EUR-based conversions.


API Reference

CurrencyConverter

Initialization

CurrencyConverter(source="BOTH", cache_dir="/tmp/rates_cache")
  • Parameters:
    • source (str): Selects the data source ("CBR", "ECB", or "BOTH"). Default is "BOTH".
    • cache_dir (str): Directory for persistent caching. Default is "/tmp/rates_cache".

Methods

  • convert(amount, from_cur, to_cur, source=None)

    • Converts an amount from one currency to another.
    • Parameters:
      • amount (float): The amount to convert.
      • from_cur (str): Source currency code.
      • to_cur (str): Target currency code.
      • source (str, optional): Specify source ("CBR", "ECB", or "BOTH"). Defaults to initialized source.
    • Returns: float (converted amount) or None if conversion is unavailable.
  • available_currencies(source=None)

    • Lists all supported currencies.
    • Parameters:
      • source (str, optional): Specify source ("CBR", "ECB", or "BOTH"). Defaults to initialized source.
    • Returns: List[str] (sorted list of supported currencies).

Development & Contributions

We welcome contributions to enhance this library! You can:

  1. Report issues or suggest features via GitHub Issues.
  2. Submit pull requests for bug fixes or new features.

Development Workflow

  1. Clone the repository:

    git clone https://github.com/markolofsen/currency-converter-free.git
    cd currency-converter-free
    
  2. Install development dependencies:

    pip install -r requirements.txt
    
  3. Run tests to verify changes:

    pytest
    

License

This project is licensed under the MIT License. For more details, refer to the LICENSE file.


About Unrealos.com

Currency Converter Free is developed and maintained by Unrealos.com, a pioneer in SaaS, PaaS, and web-service solutions. For inquiries, contact us at m@unrealos.com.

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

currency_converter_free-1.0.9.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

currency_converter_free-1.0.9-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file currency_converter_free-1.0.9.tar.gz.

File metadata

  • Download URL: currency_converter_free-1.0.9.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for currency_converter_free-1.0.9.tar.gz
Algorithm Hash digest
SHA256 51712ccf9124678e23dd9e862cdefbf29ebb8474fff2ff12e89bdabb58bb50df
MD5 059be8f004cdb9b675a869e2acab3346
BLAKE2b-256 6d9b30263be3a3b4ff91a20b79f328b18c18e0ef3731e2b2b053e8912141667d

See more details on using hashes here.

File details

Details for the file currency_converter_free-1.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for currency_converter_free-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 c3aeaf28610f89485ab8c2f7ad5d2014546540f5ebabfbc77d7e72fb5d3696ae
MD5 8416c49c91a5a52e85b34fbedfe1b200
BLAKE2b-256 4556f9669b73223b7a5696624c588a5a65b133cf3a3b5c1ca911cdf0868f01a7

See more details on using hashes here.

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