Skip to main content

Single source of truth for financial instrument data

Project description

Commodity Registry

Single source of truth for financial instrument data. Used to map ISINs, Tickers, and Names to canonical commodity identifiers for Beancount and other financial tools.

Concepts

  • Canonical Name: The unique identifier used in Beancount ledgers (e.g., AAPL, CSPX).
  • ISIN: International Securities Identification Number (e.g., US0378331005). primary key for resolution.
  • FIGI: Financial Instrument Global Identifier.
  • Ticker: Provider-specific symbol (e.g., AAPL for Yahoo, CSPX.L for Yahoo).

Installation

uv tool install commodity-registry

Configuration

The registry loads data from two sources:

  1. Bundled Data: Built-in common commodities (ETFs, Stocks).
  2. User Data: Custom YAML files located at PATH_COMMODITY_REGISTRY.

Set the environment variable to point to your custom registry:

export PATH_COMMODITY_REGISTRY=~/path/to/my/registry

The registry recursively scans this directory for .yaml and .yml files.

Usage

Resolve a Token

Find the canonical commodity for an ISIN, Ticker, or Name.

commodity-reg resolve US0378331005
# Output: Resolved: AAPL

Automatic Currency Resolution

The registry programmatically resolves standard currencies to Yahoo tickers if they are not in your custom registry:

  • resolve EUR -> EURUSD=X
  • resolve EUR/JPY -> EURJPY=X
  • resolve USD/JPY -> JPY=X

This eliminates the need to manually define standard Forex pairs in your registry files.

With price verification (checks if price matches historical data):

commodity-reg resolve US0378331005 --date 2024-01-01 --price 185.00

Add a Commodity

Add a new commodity to your local registry.

# Auto-fetch metadata from Yahoo Finance
commodity-reg add US0378331005 --fetch

# Manually specify details
commodity-reg add --name AAPL --isin US0378331005 --ticker AAPL --instrument-type Stock --asset-class Stock --currency USD

Linting

Validate your registry data and check for duplicates.

commodity-reg lint

Verify against live market data (checks if tickers are valid):

commodity-reg lint --verify

Fetch Metadata

Look up security details from online providers (Yahoo Finance, FT).

commodity-reg fetch --isin US0378331005

Programmatic Usage

You can use the registry in your Python scripts:

from commodity_registry.registry import get_registry

# Initialize registry (loads bundled data + user data from env var)
reg = get_registry()

# 1. Resolve by ISIN
commodity = reg.find_by_isin("US0378331005")
if commodity:
    print(f"Name: {commodity.name}, Currency: {commodity.currency}")

# 2. Search by any token (ISIN, Name, FIGI)
candidates = reg.find_candidates("AAPL")
for c in candidates:
    print(f"Found: {c.name} ({c.isin})")

# 3. Look up by ticker
# Note: Ticker lookup requires the provider name
comm = reg.find_by_ticker("yahoo", "AAPL")

Programmatic Usage

You can use the registry in your Python scripts:

from commodity_registry.registry import get_registry

# Initialize registry (loads bundled data + user data from env var)
reg = get_registry()

# 1. Resolve by ISIN
commodity = reg.find_by_isin("US0378331005")
if commodity:
    print(f"Name: {commodity.name}, Currency: {commodity.currency}")

# 2. Search by any token (ISIN, Name, FIGI)
candidates = reg.find_candidates("AAPL")
for c in candidates:
    print(f"Found: {c.name} ({c.isin})")

# 3. Look up by ticker
# Note: Ticker lookup requires the provider name
comm = reg.find_by_ticker("yahoo", "AAPL")

Data Format (YAML)

commodities:
  - name: AAPL
    isin: US0378331005
    instrument_type: Stock
    asset_class: Stock
    currency: USD
    tickers:
      yahoo: AAPL
    validation_points:
      - date: "2024-01-01"
        price: 185.64

Contributing

  • Bundled Data: Submit a PR to add common instruments to src/commodity_registry/data/commodities/.
  • Providers: Implement new data sources in src/commodity_registry/finder.py by adding a class that implements the DataSource interface.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

commodity_registry-0.1.6.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

commodity_registry-0.1.6-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file commodity_registry-0.1.6.tar.gz.

File metadata

  • Download URL: commodity_registry-0.1.6.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for commodity_registry-0.1.6.tar.gz
Algorithm Hash digest
SHA256 ead02b20291b2e812aa2a06264513b6197966739638474e9eed2e0764beccdd1
MD5 2f8b741f98dfb171f7b1b1f4e680ebdf
BLAKE2b-256 dbd77115103e25a1046236c49bf96eae80bd9b1c5ff8ed5e5d2d9956df106d75

See more details on using hashes here.

File details

Details for the file commodity_registry-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: commodity_registry-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for commodity_registry-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b74859c7d3645f6997de960807762ef8b7eaa7f77bb29871f73e99f3d94ad3c1
MD5 293b2769c187f2284c69c8f4612b7c42
BLAKE2b-256 d468bafc5c4518e952da1e4c1c5331a0af80a1ad04ce2dcc90c471dc41d8b236

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page