Skip to main content

hmrc-rates

HMRC exchange rates for Python, backed by the hmrc-rates Rust crate. The full published history ships inside the wheel, so Rates() is free and needs no network, parsing or I/O. All money values are decimal.Decimal and conversions are exact — the library never rounds.

Install

python3 -m pip install hmrc-rates

Python ≥ 3.10. Wheels ship for Linux (glibc and musl, x86_64 and aarch64), macOS and Windows. The sdist builds anywhere with a Rust toolchain.

Quick start

import datetime
from decimal import Decimal

from hmrc_rates import YearMonth, Rates, YearEnd

rates = Rates()

# Monthly customs/VAT rate; months can be YearMonth, datetime.date, or "YYYY-MM"
rate = rates.monthly_rate("USD", YearMonth(2025, 8))
gbp = rate.to_gbp(Decimal("2500"))  # exact — you choose the rounding
print(f"$2500 in Aug 2025 = £{gbp.quantize(Decimal('0.01'))}")

# Self Assessment style: the yearly average to 31 March 2025
eur = rates.average(YearEnd.march(2025)).rate("EUR")
print(f"EUR average, year to 31 Mar 2025: {eur.units_per_gbp}")

# Whole tables iterate as (Currency, Rate) pairs
table = rates.monthly(datetime.date(2025, 8, 15))
print(f"{len(table)} currencies in {table.period}")

"GBP" always resolves to the identity rate, and code lookups are case-insensitive.

Data coverage

One Rates value holds all four series HMRC has published:

Series Coverage Lookup
Monthly customs/VAT 2014-02 — present, no gaps monthly_rate(code, month)
Spot Dec 2010 — present, years ending 31 Mar / 31 Dec spot(year_end)
Yearly average Dec 2010 — present, years ending 31 Mar / 31 Dec average(year_end)
Weekly amendments 2014-01 — 2016-04, complete (discontinued by HMRC) weekly(date)

Currency codes are as published by HMRC, which is not always ISO 4217. E.g. Ecuador appears as ECS.

Strict lookups and exceptions

A period HMRC never published is an exception, never a silently substituted older rate. Every exception derives from HmrcRatesError (not the builtin LookupError):

  • UnknownCurrencyError — the code never appears in that series
  • PeriodNotAvailableError — no table for that period (the message includes the available range)
  • NotInPeriodError — the period exists but the currency is absent from it
  • FetchError — fetching fresh rates failed

Fallback is opt-in and visible:

rate = rates.monthly_rate_or_earlier("USD", month, 2)
rate.period  # reveals which month was actually used

Exactness

Amounts must be decimal.Decimal or int: floats raise TypeError because they are inexact. Results come back as decimal.Decimal, unrounded. Apply whatever rounding your tax context requires.

Fresh rates

Updater fetches whatever HMRC has published since this release and caches the files verbatim in the system cache directory. refreshed() performs blocking HTTP with the GIL released. cached() never touches the network.

from hmrc_rates import FetchError, Updater

updater = Updater()
try:
    rates = updater.refreshed()
except FetchError as e:
    print(f"warning: possibly stale rates: {e}")
    rates = updater.cached()  # offline fallback is an explicit choice

New HMRC publications also trigger a new patch release of this package automatically. So pinning the latest version is an alternative to runtime fetching.

Development

cd python
uv venv && uv pip install maturin pytest
VIRTUAL_ENV=$PWD/.venv .venv/bin/maturin develop
.venv/bin/pytest

The package is a PyO3 binding built with Maturin. The Rust sources live in the repository root.

Licence

MIT.

Disclaimer

This project is not affiliated with, endorsed by, or maintained by HMRC. Only the underlying rate data comes from HMRC.

Metadata

Release files for hmrc-rates 0.3.3

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

Source distribution (sdist)

Source distribution for hmrc-rates 0.3.3
File Size Uploaded
hmrc_rates-0.3.3.tar.gz 690.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for hmrc-rates 0.3.3
File
hmrc_rates-0.3.3-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
hmrc_rates-0.3.3-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
hmrc_rates-0.3.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
hmrc_rates-0.3.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
hmrc_rates-0.3.3-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64), macOS 11.0+ ARM64, macOS 10.12+ x86-64 Details

Total release size: 9.7 MB

Release files / hmrc_rates-0.3.3.tar.gz

Download URL hmrc_rates-0.3.3.tar.gz
Size 690.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e25dcb552ea44a33fc3d7e4acc67a5acfbd0a5b3a9a204026849d9401e6efeca
BLAKE2b-256 checksum
How to use checksums
168705bb16ffc11c961ef9bae3fcb1c7439af3f992fb696400e4a1e0d69e9a72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 20, 2026.

Transparency log

Release files / hmrc_rates-0.3.3-cp310-abi3-win_amd64.whl

Download URL hmrc_rates-0.3.3-cp310-abi3-win_amd64.whl
Size 1.4 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
fbbf9229150b5445023fd37e4722b72341096fb43c2e956d13dec083a8e8c586
BLAKE2b-256 checksum
How to use checksums
2f7735f71a9850a719eef769a1dd4d0bbd0862e111630d6644467e2f4f9fcd0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 20, 2026.

Transparency log

Release files / hmrc_rates-0.3.3-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL hmrc_rates-0.3.3-cp310-abi3-musllinux_1_2_x86_64.whl
Size 1.8 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
b3f4907ce6fa4d33a354f8e92f06c12470f01769b700b144083a6dba5b1de0c5
BLAKE2b-256 checksum
How to use checksums
95f8625d8da54017e6a7992b9bf5c41a7086c00cf558bf324894f33c0ffba38f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 20, 2026.

Transparency log

Release files / hmrc_rates-0.3.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL hmrc_rates-0.3.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.5 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
0140b518783ab1cfaed3e1bc303816d8902acc28d8c741c72fb4bf6287584aa3
BLAKE2b-256 checksum
How to use checksums
fd920ca534420d6ab9063f81ea6d901825d62f400df99d4d4231b7c93de54777
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 20, 2026.

Transparency log

Release files / hmrc_rates-0.3.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL hmrc_rates-0.3.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.5 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
8717df558becf2a7422365c6c58cedf327477af69a7da31c45c5c53231761c73
BLAKE2b-256 checksum
How to use checksums
ca708b920f39eb38fa9d1decd50b1cc126092176190e0e8299694af46e7db687
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 20, 2026.

Transparency log

Release files / hmrc_rates-0.3.3-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL hmrc_rates-0.3.3-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 2.8 MB
Tags CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c5df635425e783483d2445067b6ce55bab277f0c17786615c44ff5f9e0d6e45d
BLAKE2b-256 checksum
How to use checksums
c3cccb9903d1f0a7eab7169489d0db2b9d468dbf747ea6b7f019e93c659fc35d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 20, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.4

6 release files

This release

0.3.3 This release

6 release files

0.3.2

6 release files

0.3.1

6 release files

0.3.0

6 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