This project is a simple currency converter that uses real-time exchange rates. It consists of two main components:
- A Python script (
currency_convertor.py
) for fetching and converting currencies via an external API. - A web-based interface built using Streamlit (
app.py
) for users to input currencies and amounts, and view the conversion results.
- Real-time exchange rates: Get updated exchange rates from the ExchangeRate-API.
- Caching: Utilizes caching (TTLCache) to store exchange rates for 12 hours to avoid redundant API calls and improve performance.
- Web interface: Built with Streamlit, the web app allows users to select base and target currencies, input the amount, and view the converted result.
- User-friendly: The app provides feedback on when the exchange rate was last updated, as well as clear visuals to display the conversion process.
.
├── src # Source folder containing all Python files
│ ├── app.py # Streamlit web app
│ ├── currency_convertor.py # Core Python script for currency conversion
│ ├── constants.py # Currency list for dropdown (not shown)
├── README.md # Documentation file
└── requirements.txt # Python dependencies
- Python 3.x
- Internet connection for fetching exchange rates
-
Clone the repository:
git clone https://github.com/yourusername/currency-converter.git cd currency-converter
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # For Windows: venv\Scripts\activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Add your API key to the
currency_convertor.py
file: Replacecccde48f4320dc1dad4fbef5
in the API URL with your own API key from ExchangeRate-API.url = f'https://v6.exchangerate-api.com/v6/YOUR_API_KEY/latest/{base_currency}'
-
Run the Streamlit web app:
streamlit run app.py
-
Use the currency converter:
- The app will open in your default web browser.
- Select the base currency and target currency from the dropdowns.
- Input the amount of the base currency you wish to convert.
- The conversion result and exchange rate information will be displayed.
You can also run the currency conversion in the command line without using the web interface:
python currency_convertor.py
You will be prompted to input the base currency, target currency, and amount, and the conversion result will be displayed in the terminal.
- Select
IRR
(Iranian Rial) as the base currency. - Select
USD
(United States Dollar) as the target currency. - Enter
10000
as the amount. - The app will display the conversion result, the exchange rate, and the time of the last update.
$ python currency_convertor.py
Enter base currency: USD
Enter target currency: EUR
Enter amount of base currency: 100
Converted result: 92.45 # Example result
- The app uses ExchangeRate-API to fetch exchange rates.
- Exchange rates are cached for 12 hours using
cachetools
to avoid repeated API calls and improve efficiency.
Feel free to contribute to this project by forking the repository and submitting pull requests.
This project is licensed under the MIT License.
For any questions or feedback, feel free to reach out to [email protected].
Replace the placeholders such as "YOUR_API_KEY"
with your actual data and customize it based on your needs.