|
| 1 | +# forex-python |
| 2 | + |
| 3 | +[](https://travis-ci.org/MicroPyramid/forex-python) |
| 4 | +[](https://coveralls.io/github/MicroPyramid/forex-python?branch=master) |
| 5 | +[](https://landscape.io/github/MicroPyramid/forex-python/master) |
| 6 | +[](https://pypi.python.org/pypi/forex-python) |
| 7 | + |
| 8 | +**Forex Python** is a free library for foreign exchange rates and currency conversion, supporting Python 3.6 and above. |
| 9 | + |
| 10 | +> **Note:** Install the latest version (`forex-python>=1.6`) to avoid `RatesNotAvailableError`. |
| 11 | +
|
| 12 | +## Features |
| 13 | + |
| 14 | +- List all currency rates |
| 15 | +- Bitcoin price for all currencies |
| 16 | +- Convert amounts to and from Bitcoin |
| 17 | +- Get historical rates (since 1999) |
| 18 | +- Currency conversion (e.g., USD to INR) |
| 19 | +- Currency symbols and names |
| 20 | + |
| 21 | +## Currency Source |
| 22 | + |
| 23 | +[theratesapi.com](https://theratesapi.com) provides current and historical foreign exchange rates published by the European Central Bank. Rates are updated daily at 3PM CET. |
| 24 | + |
| 25 | +## Bitcoin Price Source |
| 26 | + |
| 27 | +Bitcoin prices are updated every minute. For more information, visit [CoinDesk](http://www.coindesk.com). |
| 28 | + |
| 29 | +## Installation |
| 30 | + |
| 31 | +Install via pip: |
| 32 | +```bash |
| 33 | +pip install forex-python |
| 34 | +``` |
| 35 | +Or clone the repository and install manually: |
| 36 | +```bash |
| 37 | +git clone https://github.com/MicroPyramid/forex-python.git |
| 38 | +cd forex-python |
| 39 | +python3 setup.py install |
| 40 | +``` |
| 41 | + |
| 42 | +## Usage Examples |
| 43 | + |
| 44 | +**Initialize the class:** |
| 45 | +```python |
| 46 | +from forex_python.converter import CurrencyRates |
| 47 | +c = CurrencyRates() |
| 48 | +``` |
| 49 | + |
| 50 | +**List all latest currency rates for "USD":** |
| 51 | +```python |
| 52 | +c.get_rates('USD') |
| 53 | +# Example output: {'INR': 83.12, 'EUR': 0.92, ...} |
| 54 | +``` |
| 55 | + |
| 56 | +**Get conversion rate from USD to INR:** |
| 57 | +```python |
| 58 | +c.get_rate('USD', 'INR') |
| 59 | +# Example output: 83.12 |
| 60 | +``` |
| 61 | + |
| 62 | +**Convert amount from USD to INR:** |
| 63 | +```python |
| 64 | +c.convert('USD', 'INR', 10) |
| 65 | +# Example output: 831.2 |
| 66 | +``` |
| 67 | + |
| 68 | +**Force use of Decimal:** |
| 69 | +```python |
| 70 | +from decimal import Decimal |
| 71 | +c = CurrencyRates(force_decimal=True) |
| 72 | +c.convert('USD', 'INR', Decimal('10.45')) |
| 73 | +# Example output: 868.75 |
| 74 | +``` |
| 75 | + |
| 76 | +**Get latest Bitcoin price:** |
| 77 | +```python |
| 78 | +from forex_python.bitcoin import BtcConverter |
| 79 | +b = BtcConverter() |
| 80 | +b.get_latest_price('USD') |
| 81 | +# Example output: 67000.0 |
| 82 | +``` |
| 83 | + |
| 84 | +**Convert amount to Bitcoins:** |
| 85 | +```python |
| 86 | +b.convert_to_btc(400, 'USD') |
| 87 | +# Example output: 0.00597 |
| 88 | +``` |
| 89 | + |
| 90 | +**Get currency symbol using currency code:** |
| 91 | +```python |
| 92 | +from forex_python.converter import CurrencyCodes |
| 93 | +codes = CurrencyCodes() |
| 94 | +codes.get_symbol('GBP') |
| 95 | +# Example output: '£' |
| 96 | +``` |
| 97 | + |
| 98 | +For complete documentation, see the [forex-python docs](http://forex-python.readthedocs.org/en/latest/?badge=latest). |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## Support & Feedback |
| 103 | + |
| 104 | +- Found a bug? Please [open a GitHub issue](https://github.com/MicroPyramid/forex-python/issues). |
| 105 | +- Need a new feature or custom development? [Contact us here](https://micropyramid.com/contact-us/). |
| 106 | +- Visit our [Python Development Services](https://micropyramid.com/python-development-services/) page for more information. |
| 107 | + |
| 108 | +--- |
0 commit comments