Skip to main content

occ-symbol

PyPI npm

Parse, validate, and build OCC option symbols. A tiny, dependency-free Python module (stdlib only) that turns the broker-agnostic listed-option string (the OSI symbol) into structured parts — and back again.

Python port of the occ-symbol TypeScript package — same API, same behavior, same test cases. Also on npm for JS/TS: npm install occ-symbol.

from occ_symbol import parse_occ_symbol, format_occ_symbol, is_occ_symbol, OccParts

parse_occ_symbol("SPY260825C00500000")
# OccParts(underlying='SPY', expiration='2026-08-25', right='call', strike=500.0)

format_occ_symbol(OccParts(underlying="SPY", expiration="2026-08-25", right="call", strike=500))
# "SPY260825C00500000"

is_occ_symbol("SPY260825C00500000")  # True
is_occ_symbol("SPY")                 # False

The format

An OCC (a.k.a. OSI) option symbol packs four fields into one string:

SPY260825C00500000
└┬┘└──┬─┘│└───┬──┘
 │    │  │    └── strike × 1000, 8 digits, zero-padded (00500000 = 500.000)
 │    │  └─────── C = call, P = put
 │    └────────── expiration YYMMDD (20YY)
 └─────────────── underlying / root

Install

pip install occ-symbol

Also available for JavaScript / TypeScript on npm: npm install occ-symbol.

API

Function Description
parse_occ_symbol(symbol) Parse a symbol into OccParts, or None if it isn't a valid OCC string. Tolerates space-padded roots (Schwab-style "AAPL 240119C00150000").
format_occ_symbol(parts) Build a canonical (unpadded) OCC symbol from OccParts. The inverse of parse_occ_symbol.
is_occ_symbol(symbol) True if the string is a valid OCC option symbol (padded or not).
from dataclasses import dataclass
from typing import Literal

OptionRight = Literal["call", "put"]

@dataclass(frozen=True)
class OccParts:
    underlying: str
    expiration: str  # 'YYYY-MM-DD'
    right: OptionRight
    strike: float

parse_occ_symbol and format_occ_symbol round-trip: parsing a symbol and formatting the result yields the canonical symbol, and formatting parts then parsing them returns the original parts.

Scope & limitations

  • Two-digit years are interpreted as 20YY, matching current listed-option conventions.
  • format_occ_symbol emits the canonical unpadded root; space-padded input is normalized on the round trip.
  • Strikes are scaled by 1000 (rounded to the nearest thousandth), so fractional strikes down to a tenth of a cent are preserved.

Develop

pip install -e ".[dev]"
pytest

License

MIT © John Murphy

Download files

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

Source Distribution

occ_symbol-0.1.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

occ_symbol-0.1.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file occ_symbol-0.1.1.tar.gz.

File metadata

  • Download URL: occ_symbol-0.1.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.5

File hashes

Hashes for occ_symbol-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ff27e9f680cebf4dd7be2d7f7db877d59f71e3e3a025c41b662e0f014ec1a3d0
MD5 4798ea4ffb364aca89e01627b4cbc919
BLAKE2b-256 29297bcd6788332543b4dfbbc4e798fa91c4c70b72113037a7dce83ec311415b

See more details on using hashes here.

File details

Details for the file occ_symbol-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: occ_symbol-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.5

File hashes

Hashes for occ_symbol-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f698a2868e4861b1c67b6548273ce11fe71dd860d005a5a61baa2076fe98f782
MD5 168afe58e69059db50661523bf344212
BLAKE2b-256 1c980e333703ef11a045bf664827b1048fba5342b4d3784c9a021ed1e6d39f93

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 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