Skip to content

Commit 6433f0a

Browse files
committed
Add README.md and update version to 1.9.2 in setup.py and conf.py; enhance rate handling in converter.py
1 parent 40dfe0f commit 6433f0a

File tree

5 files changed

+114
-165
lines changed

5 files changed

+114
-165
lines changed

README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# forex-python
2+
3+
[![travis-ci](https://travis-ci.org/MicroPyramid/forex-python.svg?branch=master)](https://travis-ci.org/MicroPyramid/forex-python)
4+
[![coveralls](https://coveralls.io/repos/github/MicroPyramid/forex-python/badge.svg?branch=master)](https://coveralls.io/github/MicroPyramid/forex-python?branch=master)
5+
[![Code Health](https://landscape.io/github/MicroPyramid/forex-python/master/landscape.svg?style=flat)](https://landscape.io/github/MicroPyramid/forex-python/master)
6+
[![pypi](https://img.shields.io/badge/python-3.6%2B-blue.svg)](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+
---

README.rst

Lines changed: 0 additions & 162 deletions
This file was deleted.

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
# built documents.
6060
#
6161
# The short X.Y version.
62-
version = u'1.9'
62+
version = u'1.9.2'
6363
# The full version, including alpha/beta/rc tags.
64-
release = u'1.9'
64+
release = u'1.9.2'
6565

6666
# The language for content autogenerated by Sphinx. Refer to documentation
6767
# for a list of supported languages.

forex_python/converter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ def convert(self, base_cur, dest_cur, amount, date_obj=None):
9999
if not rate:
100100
raise RatesNotAvailableError("Currency {0} => {1} rate not available for Date {2}.".format(
101101
source_url, dest_cur, date_str))
102+
# Ensure rate is numeric
103+
if isinstance(rate, str):
104+
rate = Decimal(rate) if use_decimal else float(rate)
102105
try:
103106
converted_amount = rate * amount
104107
return converted_amount

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup, find_packages
44

55
# 1) Bump this version each release:
6-
VERSION = '1.9'
6+
VERSION = '1.9.2'
77

88
# 2) Pull your README.md in as long_description:
99
here = os.path.abspath(os.path.dirname(__file__))

0 commit comments

Comments
 (0)