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 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_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
Metadata
Release files for occ-symbol 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| occ_symbol-0.1.1.tar.gz | 5.1 kB | Without provenance | Details for occ_symbol-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| occ_symbol-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for occ_symbol-0.1.1-py3-none-any.whl |
Total release size: 10.4 kB
Release files / occ_symbol-0.1.1.tar.gz
| Download URL | occ_symbol-0.1.1.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff27e9f680cebf4dd7be2d7f7db877d59f71e3e3a025c41b662e0f014ec1a3d0
|
|
BLAKE2b-256 checksum How to use checksums |
29297bcd6788332543b4dfbbc4e798fa91c4c70b72113037a7dce83ec311415b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.5
|
Release files / occ_symbol-0.1.1-py3-none-any.whl
| Download URL | occ_symbol-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f698a2868e4861b1c67b6548273ce11fe71dd860d005a5a61baa2076fe98f782
|
|
BLAKE2b-256 checksum How to use checksums |
1c980e333703ef11a045bf664827b1048fba5342b4d3784c9a021ed1e6d39f93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.5
|
Security for occ-symbol 0.1.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.