Currency Symbols
A tiny Python library (version 2.0.4) that provides currency symbols by their ISO 4217 currency codes. It's actively maintained with a focus on simple lookups and no external dependencies, making it suitable for applications needing quick access to currency symbols.
Warnings
- breaking Version 1.0.0 (released August 2021) introduced a breaking change by switching from a default export to a named export. For Python users, this means ensuring you explicitly import the `CurrencySymbols` class (`from currency_symbols import CurrencySymbols`) rather than relying on previous module-level access patterns.
- gotcha This library is designed solely to retrieve the Unicode symbol for a given currency code. It does NOT provide functionality for currency formatting (e.g., adding thousands separators, decimal precision, locale-specific symbol placement), currency conversion, or exchange rates. For such features, consider libraries like `locale`, `Babel`, or `forex-python`.
- gotcha The project's GitHub README contains usage examples for both Python and JavaScript. Always ensure you are following the Python-specific examples and import patterns to avoid confusion, which consistently use `from currency_symbols import CurrencySymbols`.
- gotcha When an invalid or unknown currency code is provided to `CurrencySymbols.get_symbol()`, the method returns `None`. Your application code should handle this `None` return value gracefully to prevent errors.
Install
-
pip install currency-symbols
Imports
- CurrencySymbols
from currency_symbols import CurrencySymbols
Quickstart
from currency_symbols import CurrencySymbols
dollar_symbol = CurrencySymbols.get_symbol('USD')
euro_symbol = CurrencySymbols.get_symbol('EUR')
print(f"USD: {dollar_symbol}")
print(f"EUR: {euro_symbol}")
# Handling an invalid currency code
invalid_symbol = CurrencySymbols.get_symbol('XXX')
print(f"XXX: {invalid_symbol} (Expected None for invalid code)")