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.2

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.2
File Size Uploaded
hmrc_rates-0.3.2.tar.gz 686.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for hmrc-rates 0.3.2
File
hmrc_rates-0.3.2-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
hmrc_rates-0.3.2-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
hmrc_rates-0.3.2-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.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
hmrc_rates-0.3.2-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.10 abi3 macOS 11.0+ ARM64, macOS 10.12+ x86-64, macOS 10.12+ universal2 (ARM64, x86-64) Details

Total release size: 9.7 MB

Release files / hmrc_rates-0.3.2.tar.gz

Download URL hmrc_rates-0.3.2.tar.gz
Size 686.5 kB
Tags Source
SHA-256 checksum
How to use checksums
34c30eed00fcc274debc0357941a73ae768ef9b26c88a001716e9c59455d462c
BLAKE2b-256 checksum
How to use checksums
3102e825801d9494d36e99f22466d2a326032915f0616f48bcca3b92def652fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

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

Download URL hmrc_rates-0.3.2-cp310-abi3-win_amd64.whl
Size 1.4 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
b0b2b53c3635485949b064445b23211a8127d632fb6b585e69c92234b2a442d4
BLAKE2b-256 checksum
How to use checksums
7dbdf172997c8b48cd0944f756dac3dd630a53394521da18567976b9526a59d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

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

Download URL hmrc_rates-0.3.2-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
06c50a6c2c9a68f958b6f7c2758788e998b980eb662d8b2d274d30550ece636f
BLAKE2b-256 checksum
How to use checksums
ae4d447f6a92f6818314f483d0dc2019a765aaaaa7a3e8bee4c4da95d30fbdff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

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

Download URL hmrc_rates-0.3.2-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
4535d406fa0b7742c317534ea7512d5cfbd6c34f8316a66b8885e8a6c7ca38d2
BLAKE2b-256 checksum
How to use checksums
d2d6a8a8ca7fc64493aacac21fc9c0b5fea77068c5bad02cdbb6824e363daed0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

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

Download URL hmrc_rates-0.3.2-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
437df71dc396025baeb267ca894459a28271c4eec603c820decd279a28aa0285
BLAKE2b-256 checksum
How to use checksums
00048f1c062177e4edc22c6f4ea27c895266e96586bcce39a488f25c01552bbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

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

Download URL hmrc_rates-0.3.2-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
3b10b01a6db3a59272a5e6623b91d177ba69c7d5ff54acfb8b32ba92ed1923de
BLAKE2b-256 checksum
How to use checksums
06cf76a47ad6e796a7ae9de4f43f02d1f024a2992fb9efbfa7970fb35f025d99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.4

6 release files

0.3.3

6 release files

This release

0.3.2 This release

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