pydantic-market-data
Shared Pydantic models and interfaces for financial data sources.
Defines a standard contract (DataSource) and data structures (OHLCV, Security, History) to ensure interoperability between finance packages.
Installation
pip install pydantic-market-data
Usage
Models
Standardized data models for financial entities.
from pydantic_market_data.models import Security, OHLCV, SecurityQuery
# Security Definition
s = Security(
symbol="AAPL",
name="Apple Inc.",
exchange="NASDAQ",
currency="USD",
asset_class="equity", # AssetClass value
isin="US0378331005"
)
# Historical Data Point
candle = OHLCV(
date="2023-12-01", # Coerced to FlexibleDatetime
open=150.0,
high=155.0,
low=149.0,
close=154.0,
volume=50000000
)
# Security Lookup Query
query = SecurityQuery(
symbol="AAPL",
asset_class="equity",
price_on={"price": 190.0, "date": "2023-12-01"} # Known price, coerced to list[PriceOnDate]
)
Protocol
Implement the DataSource protocol to create compatible data providers.
from pydantic_market_data.interfaces import DataSource
from pydantic_market_data.models import SecurityQuery, Security, History, Symbol, HistoryPeriod
class MySource(DataSource):
def resolve(self, criteria: SecurityQuery) -> Security | None:
# Implementation...
pass
def history(self, symbol: Symbol.Input, period: HistoryPeriod = HistoryPeriod.MO1) -> History:
# Implementation...
pass
def search(self, query: str) -> list[Security]:
# Implementation...
pass
# ...plus get_price() and validate()
CLI Support
The package provides optimized pydantic-settings models for building professional CLI tools.
from pydantic_market_data.cli_models import SearchArgs, PatchedCliSettingsSource
from pydantic_settings import BaseSettings, CliSubCommand
class MyCliSettings(BaseSettings):
search: CliSubCommand[SearchArgs]
@classmethod
def settings_customise_sources(cls, settings_cls, **kwargs):
return (PatchedCliSettingsSource(settings_cls, cli_parse_args=True),)
# Usage:
# my-tool search --symbol AAPL -vv --format json
Key CLI features:
- Clean Help: Automatically removes default values from help text for a cleaner look.
- Improved Flags: Normalizes double-dash flags like
--vvto-vv. - JSON Schema: Adds a
--schemaflag to output the interface definition. - Consistent Defaults: Whatever order your
BaseSettingssubclass lists its bases in, multi-word fields become--asset-class,-v/-vvare valueless flags, and optional values show as--symbol SYMBOL(not{SYMBOL,null}). Passcli_kebab_case,cli_implicit_flagsorcli_hide_none_typeto the source to override. - Metavars: Custom types (
SYMBOL,ISIN, etc.) provide descriptive help labels.
SearchArgs and HistoryArgs are SecurityQueryArgs and HistoryQueryArgs plus GlobalArgs (-v, -vv, --format, --schema). SearchArgs also adds --limit, a paging option that list-command frameworks are expected to own. If your CLI framework already owns those options, use the domain-only *QueryArgs models instead:
from pydantic_market_data import SecurityQueryArgs
class SearchCommand(SecurityQueryArgs):
pass # --symbol, --isin, ... without -v/--format/--schema/--limit
License
MIT
Metadata
Release files for pydantic-market-data 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pydantic_market_data-0.6.0.tar.gz | 25.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydantic_market_data-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.2 kB
Release files / pydantic_market_data-0.6.0.tar.gz
| Download URL | pydantic_market_data-0.6.0.tar.gz |
|---|---|
| Size | 25.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1bd0e814c71ccf55b495f228a1b36a0abc60fc27d1100ede1acaf8fded6077f8
|
|
BLAKE2b-256 checksum How to use checksums |
5f499e6ee48477f35b95878fc6d0c947f9faee28e137fcbadc5aea5ca436ddba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","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}
|
Release files / pydantic_market_data-0.6.0-py3-none-any.whl
| Download URL | pydantic_market_data-0.6.0-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
598f2ba937de34b25a7ae114d6da1b3492a79a9f32d9caed0d293138f037749c
|
|
BLAKE2b-256 checksum How to use checksums |
d8649b1e4f896990adada12273f9c3978bf52fe0a8a2061eb1b703ddaf7c6eb7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","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}
|