Skip to main content

Currex

currex version - PyPI PyPI status MIT license - PyPI Python version - PyPI GitHub Actions: Build GitHub Actions: Linting Twitter @pmigdal

A Pythonic currency calculator that makes working with currencies and exchange rates simple and smooth - by Piotr Migdał. See it in action in Colab - no need to install anything.

I often use Python as a command-line calculator. However, I frequently found myself going back to Google Search to convert between currencies. So, I created this library to make it easy to add, multiply, and convert between currencies. One of its core features is autocasting - when working with multiple currencies, it automatically converts them to match the first currency used.

This library is designed for use in interactive Python sessions (such as Jupyter Notebook, Jupyter Lab, or IPython) to quickly get ballpark price estimates - perfect for travel planning or online shopping. I personally use it through IPython on the command line.

Right now it uses HexaRate for exchange rates.

It is a new package, so I'm open to suggestions.

Disclaimer

It is NOT intended to be used in production code. Every API design decision was made to optimize for interactive sessions. Some decisions consciously go against best practices for production libraries. For example, the main namespace defines all currencies as constants, and the example code uses from currex import * - practices I believe are appropriate for interactive sessions only.

EVEN MORE IMPORTANT: Never use it for any important decisions - taxes, investments, etc. There is no guarantee that the exchange rates are up-to-date and correct. Note that even major players make mistakes, e.g. Google Glitch Undervalues Poland's Zloty By A Fifth. Always use the official exchange rates.

Installation

pip install currex

Usage

from currex import *

# use currencies as if they were numbers
100 * USD  # USD(100.00)
12 * USD(100)  # USD(1200.00)

# convert currencies to other currencies
USD(100).to(EUR)  # EUR(85.30)
USD(100).to(PLN)  # PLN(430.50)

# this syntax is also supported
PLN(EUR(12))  # PLN(51.33)

# add different currencies
USD(100) + EUR(100)  # USD(203.42)
EUR(100) - USD(100)  # EUR(3.22)

# divide currencies
USD(2) / JPY(14)  # 22.531428526365715

# configure decimal digits (default is 2)
currex_config.set_decimal_digits(3)  # show 3 decimal places
USD(123.456789)  # USD(123.457)
currex_config.set_decimal_digits(None)  # show full precision
USD(123.456789)  # USD(123.456789)

For a slightly more advanced use, there is a general Currency class:

from currex import Currency

USD = Currency("USD")  # one dollar

money = Currency("USD", 100)  # USD(100.00)
money.to("EUR")  # EUR(95.30)

Features

  • Arithmetic operations with currencies
  • Currency conversion
  • Autocasting - when using a few currencies, automatically convert them to the first one
  • Configurable decimal places for currency representation

Requirements

  • Python 3.9 or higher
  • Internet connection for real-time exchange rates

Development

To set up the development environment:

git clone git@github.com:stared/currex.git
cd currex
pip install -e .[dev]

TODO

  • Mock API for testing
  • More backends for exchange rates, see e.g. this list
  • Support for cryptocurrencies

License

MIT License by Piotr Migdał

Metadata

Release files for currex 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for currex 0.2.0
File Size Uploaded
currex-0.2.0.tar.gz 12.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for currex 0.2.0
File Interpreter ABI Platform
currex-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.1 kB

Release files / currex-0.2.0.tar.gz

Download URL currex-0.2.0.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0d891dec259ad2115f5acf41b91784882f648e127a1a008b7e02e15f3a7c6f05
BLAKE2b-256 checksum
How to use checksums
365af264572d2162e7efe18a39a49a106a9ef849533788440e8ab5bd48434f1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 25, 2025.

Transparency log

Release files / currex-0.2.0-py3-none-any.whl

Download URL currex-0.2.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c680428a4478bd8ca5de768f28b820961b738bae9d387c97332d4351bf7128b4
BLAKE2b-256 checksum
How to use checksums
9d627ae9b15aa166bffc55aa08170e3a6e6e34b74c2fcc4fbe2876f185b41f86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 25, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page