currency-converter-free


Namecurrency-converter-free JSON
Version 1.0.8 PyPI version JSON
download
home_pagehttps://github.com/markolofsen/currency-converter-free
SummaryA robust and free currency converter module for Python, supporting multiple sources like ECB and CBR.
upload_time2024-12-21 11:22:19
maintainerNone
docs_urlNone
authorUnrealos Team
requires_python>=3.7
licenseNone
keywords currency converter python currency api free currency rates cbr ecb foreign exchange money conversion
VCS
bugtrack_url
requirements requests diskcache cachetools
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Currency Converter Free

Currency Converter Free is a Python library designed to fetch and combine exchange rates from two trusted sources: the Central Bank of Russia (CBR) and the European Central Bank (ECB). The library provides an easy-to-use interface for currency conversion and employs disk-based caching mechanisms for optimal performance.

## Key Features

- **Multiple Data Sources**: Fetch exchange rates from both the CBR and ECB, ensuring comprehensive coverage of currencies.
- **Disk-Based Caching**: Utilizes persistent disk caching to store exchange rates, reducing unnecessary API calls and enhancing performance.
- **Automatic Base Currency Handling**: Transparently manages base currency differences between CBR (RUB) and ECB (EUR).
- **Easy Conversion**: Convert between any two supported currencies with a single function call.
- **Extensible**: Easily adaptable for additional data sources or custom fetchers.

## Installation

Install the library using pip:

```bash
pip install currency-converter-free
```

## Requirements

- Python 3.7+
- [Requests](https://pypi.org/project/requests/)
- [DiskCache](https://pypi.org/project/diskcache/)

## Installation of Dependencies

If not using `pip` to install `currency-converter-free`, ensure all dependencies are installed:

```bash
pip install requests diskcache
```

## Usage

### Basic Example

```python
from currency_converter_free import CurrencyConverter

# Initialize the converter with default settings (both CBR and ECB sources)
converter = CurrencyConverter()

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

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

# List all available currencies
available_currencies = converter.available_currencies()
print("Available currencies:", available_currencies)
```

### Advanced Options

#### Specifying Data Source

The `source` parameter allows you to choose the data source for fetching exchange rates. You can specify `"CBR"`, `"ECB"`, or `"BOTH"` to use both sources simultaneously.

```python
from currency_converter_free import CurrencyConverter

# Initialize the converter to use only CBR rates
converter_cbr = CurrencyConverter(source="CBR")

# Initialize the converter to use only ECB rates
converter_ecb = CurrencyConverter(source="ECB")

# Initialize the converter to use both CBR and ECB rates
converter_both = CurrencyConverter(source="BOTH")
```

**Parameters:**

- `source` (str): The source for exchange rates. Accepted values are:
  - `"CBR"`: Use only the Central Bank of Russia rates.
  - `"ECB"`: Use only the European Central Bank rates.
  - `"BOTH"`: Combine rates from both CBR and ECB for comprehensive coverage.
  
**Default:** `"BOTH"`

#### Customizing Cache Directory

Specify a custom directory for storing cached exchange rates. This is useful for persisting cache across different environments or systems.

```python
from currency_converter_free import CurrencyConverter

# Initialize the converter with a custom cache directory
converter = CurrencyConverter(cache_dir="/path/to/your/cache_directory")
```

**Parameters:**

- `cache_dir` (str): The directory path where cached exchange rates will be stored.

**Default:** `"/tmp/rates_cache"`

## Supported Sources

- **Central Bank of Russia (CBR)**: Provides exchange rates with the Russian Ruble (RUB) as the base currency.
- **European Central Bank (ECB)**: Offers exchange rates with the Euro (EUR) as the base currency.

The library intelligently combines rates from both sources, prioritizing CBR for RUB-based conversions and ECB for EUR-based conversions when using the `"BOTH"` option.

## API Reference

### `CurrencyConverter` Class

#### `__init__(self, source="BOTH", cache_dir="/tmp/rates_cache")`

Initialize the CurrencyConverter with default source and disk-based caching.

- **Parameters:**
  - `source` (str): The default source for rates. Accepted values are `"CBR"`, `"ECB"`, or `"BOTH"`. Defaults to `"BOTH"`.
  - `cache_dir` (str): Directory for persistent cache. Defaults to `"/tmp/rates_cache"`.

#### `convert(self, amount, from_cur, to_cur, source=None)`

Convert an amount between currencies using specified or default source rates.

- **Parameters:**
  - `amount` (float): The amount to convert.
  - `from_cur` (str): The source currency code.
  - `to_cur` (str): The target currency code.
  - `source` (str, optional): The source to use (`"CBR"`, `"ECB"`, or `"BOTH"`). Defaults to the initialized source.

- **Returns:**
  - `float` or `None`: The converted amount or `None` if conversion is not possible.

#### `available_currencies(self, source=None)`

List all available currencies for conversion.

- **Parameters:**
  - `source` (str, optional): The source to use (`"CBR"`, `"ECB"`, or `"BOTH"`). Defaults to the initialized source.

- **Returns:**
  - `List[str]`: A sorted list of available currency codes.

## Contributing

We welcome contributions to improve this library. Please submit issues or pull requests via our [GitHub repository](https://github.com/markolofsen/currency-converter-free).

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

## About Unrealos.com

Currency Converter Free is developed and maintained by [Unrealos.com](https://unrealos.com), a company specializing in SaaS, PaaS, and web-service solutions. For inquiries, please contact us at [m@unrealos.com](mailto:m@unrealos.com).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/markolofsen/currency-converter-free",
    "name": "currency-converter-free",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "currency converter, python currency API, free currency rates, CBR, ECB, foreign exchange, money conversion",
    "author": "Unrealos Team",
    "author_email": "m@unrealos.com",
    "download_url": "https://files.pythonhosted.org/packages/89/7e/9f64d8be553653800d0b87723aae4ec210ce6eb2d8c647a791dafb0d5567/currency_converter_free-1.0.8.tar.gz",
    "platform": null,
    "description": "\n# Currency Converter Free\n\nCurrency Converter Free is a Python library designed to fetch and combine exchange rates from two trusted sources: the Central Bank of Russia (CBR) and the European Central Bank (ECB). The library provides an easy-to-use interface for currency conversion and employs disk-based caching mechanisms for optimal performance.\n\n## Key Features\n\n- **Multiple Data Sources**: Fetch exchange rates from both the CBR and ECB, ensuring comprehensive coverage of currencies.\n- **Disk-Based Caching**: Utilizes persistent disk caching to store exchange rates, reducing unnecessary API calls and enhancing performance.\n- **Automatic Base Currency Handling**: Transparently manages base currency differences between CBR (RUB) and ECB (EUR).\n- **Easy Conversion**: Convert between any two supported currencies with a single function call.\n- **Extensible**: Easily adaptable for additional data sources or custom fetchers.\n\n## Installation\n\nInstall the library using pip:\n\n```bash\npip install currency-converter-free\n```\n\n## Requirements\n\n- Python 3.7+\n- [Requests](https://pypi.org/project/requests/)\n- [DiskCache](https://pypi.org/project/diskcache/)\n\n## Installation of Dependencies\n\nIf not using `pip` to install `currency-converter-free`, ensure all dependencies are installed:\n\n```bash\npip install requests diskcache\n```\n\n## Usage\n\n### Basic Example\n\n```python\nfrom currency_converter_free import CurrencyConverter\n\n# Initialize the converter with default settings (both CBR and ECB sources)\nconverter = CurrencyConverter()\n\n# Convert 100 USD to EUR\namount_in_eur = converter.convert(100, 'USD', 'EUR')\nprint(f\"100 USD = {amount_in_eur:.2f} EUR\")\n\n# Convert 100 RUB to USD\namount_in_usd = converter.convert(100, 'RUB', 'USD')\nprint(f\"100 RUB = {amount_in_usd:.2f} USD\")\n\n# List all available currencies\navailable_currencies = converter.available_currencies()\nprint(\"Available currencies:\", available_currencies)\n```\n\n### Advanced Options\n\n#### Specifying Data Source\n\nThe `source` parameter allows you to choose the data source for fetching exchange rates. You can specify `\"CBR\"`, `\"ECB\"`, or `\"BOTH\"` to use both sources simultaneously.\n\n```python\nfrom currency_converter_free import CurrencyConverter\n\n# Initialize the converter to use only CBR rates\nconverter_cbr = CurrencyConverter(source=\"CBR\")\n\n# Initialize the converter to use only ECB rates\nconverter_ecb = CurrencyConverter(source=\"ECB\")\n\n# Initialize the converter to use both CBR and ECB rates\nconverter_both = CurrencyConverter(source=\"BOTH\")\n```\n\n**Parameters:**\n\n- `source` (str): The source for exchange rates. Accepted values are:\n  - `\"CBR\"`: Use only the Central Bank of Russia rates.\n  - `\"ECB\"`: Use only the European Central Bank rates.\n  - `\"BOTH\"`: Combine rates from both CBR and ECB for comprehensive coverage.\n  \n**Default:** `\"BOTH\"`\n\n#### Customizing Cache Directory\n\nSpecify a custom directory for storing cached exchange rates. This is useful for persisting cache across different environments or systems.\n\n```python\nfrom currency_converter_free import CurrencyConverter\n\n# Initialize the converter with a custom cache directory\nconverter = CurrencyConverter(cache_dir=\"/path/to/your/cache_directory\")\n```\n\n**Parameters:**\n\n- `cache_dir` (str): The directory path where cached exchange rates will be stored.\n\n**Default:** `\"/tmp/rates_cache\"`\n\n## Supported Sources\n\n- **Central Bank of Russia (CBR)**: Provides exchange rates with the Russian Ruble (RUB) as the base currency.\n- **European Central Bank (ECB)**: Offers exchange rates with the Euro (EUR) as the base currency.\n\nThe library intelligently combines rates from both sources, prioritizing CBR for RUB-based conversions and ECB for EUR-based conversions when using the `\"BOTH\"` option.\n\n## API Reference\n\n### `CurrencyConverter` Class\n\n#### `__init__(self, source=\"BOTH\", cache_dir=\"/tmp/rates_cache\")`\n\nInitialize the CurrencyConverter with default source and disk-based caching.\n\n- **Parameters:**\n  - `source` (str): The default source for rates. Accepted values are `\"CBR\"`, `\"ECB\"`, or `\"BOTH\"`. Defaults to `\"BOTH\"`.\n  - `cache_dir` (str): Directory for persistent cache. Defaults to `\"/tmp/rates_cache\"`.\n\n#### `convert(self, amount, from_cur, to_cur, source=None)`\n\nConvert an amount between currencies using specified or default source rates.\n\n- **Parameters:**\n  - `amount` (float): The amount to convert.\n  - `from_cur` (str): The source currency code.\n  - `to_cur` (str): The target currency code.\n  - `source` (str, optional): The source to use (`\"CBR\"`, `\"ECB\"`, or `\"BOTH\"`). Defaults to the initialized source.\n\n- **Returns:**\n  - `float` or `None`: The converted amount or `None` if conversion is not possible.\n\n#### `available_currencies(self, source=None)`\n\nList all available currencies for conversion.\n\n- **Parameters:**\n  - `source` (str, optional): The source to use (`\"CBR\"`, `\"ECB\"`, or `\"BOTH\"`). Defaults to the initialized source.\n\n- **Returns:**\n  - `List[str]`: A sorted list of available currency codes.\n\n## Contributing\n\nWe welcome contributions to improve this library. Please submit issues or pull requests via our [GitHub repository](https://github.com/markolofsen/currency-converter-free).\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## About Unrealos.com\n\nCurrency Converter Free is developed and maintained by [Unrealos.com](https://unrealos.com), a company specializing in SaaS, PaaS, and web-service solutions. For inquiries, please contact us at [m@unrealos.com](mailto:m@unrealos.com).\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A robust and free currency converter module for Python, supporting multiple sources like ECB and CBR.",
    "version": "1.0.8",
    "project_urls": {
        "Bug Tracker": "https://github.com/markolofsen/currency-converter-free/issues",
        "Changelog": "https://github.com/markolofsen/currency-converter-free/releases",
        "Documentation": "https://github.com/markolofsen/currency-converter-free#readme",
        "Homepage": "https://github.com/markolofsen/currency-converter-free",
        "Source Code": "https://github.com/markolofsen/currency-converter-free"
    },
    "split_keywords": [
        "currency converter",
        " python currency api",
        " free currency rates",
        " cbr",
        " ecb",
        " foreign exchange",
        " money conversion"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "57096a5707a8544d0619f7a4f56b0f58da91f2248882ea6544d5b3765893653c",
                "md5": "d4a7ebc3dfd99624b2e2fccc0bc87f2f",
                "sha256": "7982e1466ba36ef630addcffba21c9ad47626829ce3d4520b744ea9181d048c4"
            },
            "downloads": -1,
            "filename": "currency_converter_free-1.0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d4a7ebc3dfd99624b2e2fccc0bc87f2f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7370,
            "upload_time": "2024-12-21T11:22:18",
            "upload_time_iso_8601": "2024-12-21T11:22:18.594083Z",
            "url": "https://files.pythonhosted.org/packages/57/09/6a5707a8544d0619f7a4f56b0f58da91f2248882ea6544d5b3765893653c/currency_converter_free-1.0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "897e9f64d8be553653800d0b87723aae4ec210ce6eb2d8c647a791dafb0d5567",
                "md5": "e19f7079725ca7ae363f37985401d9a3",
                "sha256": "041dfdd563f164e19071af9cf5379f19f194eec869527e5a55aeb124ef58852d"
            },
            "downloads": -1,
            "filename": "currency_converter_free-1.0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "e19f7079725ca7ae363f37985401d9a3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 6801,
            "upload_time": "2024-12-21T11:22:19",
            "upload_time_iso_8601": "2024-12-21T11:22:19.913091Z",
            "url": "https://files.pythonhosted.org/packages/89/7e/9f64d8be553653800d0b87723aae4ec210ce6eb2d8c647a791dafb0d5567/currency_converter_free-1.0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-21 11:22:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "markolofsen",
    "github_project": "currency-converter-free",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "diskcache",
            "specs": []
        },
        {
            "name": "cachetools",
            "specs": []
        }
    ],
    "lcname": "currency-converter-free"
}
        
Elapsed time: 0.40048s