occ-symbol
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-symbolTypeScript package. Same behavior, same test cases.
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
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_symbolemits 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file occ_symbol-0.1.0.tar.gz.
File metadata
- Download URL: occ_symbol-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1ce64a64d5488cdb94bbdf37de0f24f63fe6915def49a37abfff7492ac4e95d
|
|
| MD5 |
521cacddfde475c338877722caa7388d
|
|
| BLAKE2b-256 |
4c1f507d4f64a3d15fb0915c0595f2db8c4399c6100c070504f12cc76a83ccdd
|
File details
Details for the file occ_symbol-0.1.0-py3-none-any.whl.
File metadata
- Download URL: occ_symbol-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a34dd7c62a33272f79ab1efd47ab17adf9d0c3aca2ccd81547aa4a8da0f05ae8
|
|
| MD5 |
d2431d10de0f18e0bc5e68716604833b
|
|
| BLAKE2b-256 |
943ac6be71282b4dfaaaf558786de9d93f877ca983a3d478ca353841f00525ed
|