Skip to main content

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.

Metadata

Release files for currency-converter-free 1.0.9

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

Source distribution (sdist)

Source distribution for currency-converter-free 1.0.9
File Size Uploaded
currency_converter_free-1.0.9.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for currency-converter-free 1.0.9
File Interpreter ABI Platform
currency_converter_free-1.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / currency_converter_free-1.0.9.tar.gz

Download URL currency_converter_free-1.0.9.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
51712ccf9124678e23dd9e862cdefbf29ebb8474fff2ff12e89bdabb58bb50df
BLAKE2b-256 checksum
How to use checksums
6d9b30263be3a3b4ff91a20b79f328b18c18e0ef3731e2b2b053e8912141667d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release files / currency_converter_free-1.0.9-py3-none-any.whl

Download URL currency_converter_free-1.0.9-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3aeaf28610f89485ab8c2f7ad5d2014546540f5ebabfbc77d7e72fb5d3696ae
BLAKE2b-256 checksum
How to use checksums
4556f9669b73223b7a5696624c588a5a65b133cf3a3b5c1ca911cdf0868f01a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

1.0.9 This release

2 release files

1.0.8

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.0

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