
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
django-currency-converter-erapi
Advanced tools
A Django application for currency conversion using real-time exchange rates
A Django application for converting currencies using real-time exchange rates from ExchangeRate-API.
pip install django-currency-converter-erapi
pip install django-currency-converter-erapi[dotenv]
currency_converter
to your Django project's INSTALLED_APPS
in settings.py
:INSTALLED_APPS = [
# ... other apps
'currency_converter_erapi',
]
The currency converter supports multiple ways to configure your API key for premium access:
Create a .env
file in your Django project root:
# .env file
CURRENCY_API_KEY=your_exchangerate_api_key_here
# or alternatively:
EXCHANGERATE_API_KEY=your_exchangerate_api_key_here
Add to your Django settings.py
:
CURRENCY_API_KEY = 'your_api_key_here'
Set environment variables directly:
export CURRENCY_API_KEY=your_api_key_here
# or
export EXCHANGERATE_API_KEY=your_api_key_here
The package checks for API keys in this order:
CURRENCY_API_KEY
)CURRENCY_API_KEY
EXCHANGERATE_API_KEY
Add these optional settings to your Django settings.py
:
# Currency Converter Settings (Optional)
CURRENCY_CACHE_TIMEOUT = 3600 # Cache exchange rates for 1 hour (default: 3600)
# Ensure you have caching configured
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
}
}
Convert currency using the management command:
# Basic conversion
python manage.py convert_currency 100 USD EUR
# Show only exchange rate
python manage.py convert_currency 100 USD EUR --rate-only
# List all supported currencies
python manage.py convert_currency 0 USD EUR --list-currencies
from currency_converter_erapi.converter import CurrencyConverter
from currency_converter_erapi.exceptions import InvalidCurrencyError, APIError
try:
converter = CurrencyConverter()
# Convert 100 USD to EUR
result = converter.convert(100, 'USD', 'EUR')
print(f"100 USD = {result} EUR")
# Get exchange rate only
rate = converter.get_exchange_rate('USD', 'EUR')
print(f"1 USD = {rate} EUR")
# Get supported currencies
currencies = converter.get_supported_currencies()
print(f"Supported currencies: {currencies}")
except InvalidCurrencyError as e:
print(f"Invalid currency: {e}")
except APIError as e:
print(f"API error: {e}")
The application supports 24 major currencies:
The package includes comprehensive error handling:
InvalidCurrencyError
: Raised for unsupported currency codesAPIError
: Raised when the exchange rate API failsRateLimitError
: Raised when API rate limits are exceededNetworkError
: Raised for network connectivity issuesCacheError
: Raised for caching-related errorsThe free ExchangeRate-API has the following limits:
For higher limits, consider upgrading to a paid plan and setting CURRENCY_API_KEY
.
python -m pytest
The project follows PEP 8 standards and includes:
API Rate Limit Exceeded
Network Timeout
Cache Issues
Invalid Currency Code
Enable logging to see detailed error information:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'currency_converter_erapi': {
'handlers': ['console'],
'level': 'INFO',
},
},
}
git checkout -b feature/amazing-feature
)git commit -m 'Add amazing feature'
)git push origin feature/amazing-feature
)This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
FAQs
A Django application for currency conversion using real-time exchange rates
We found that django-currency-converter-erapi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.