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. The top-levelpydantic_market_data.ISINis the validating value object; theISINmetavar lives inpydantic_market_data.cli_models.
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.10.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 | Provenance | Actions |
|---|---|---|---|---|
| pydantic_market_data-0.10.0.tar.gz | 36.1 kB | Without provenance | Details for pydantic_market_data-0.10.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydantic_market_data-0.10.0-py3-none-any.whl | Python 3 | none | any | Details for pydantic_market_data-0.10.0-py3-none-any.whl |
Total release size: 50.5 kB
Release files / pydantic_market_data-0.10.0.tar.gz
| Download URL | pydantic_market_data-0.10.0.tar.gz |
|---|---|
| Size | 36.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7369d39990dd6fa2f9ad6f78ae69d6048d301c773b318096fb47c383e37a53c2
|
|
BLAKE2b-256 checksum How to use checksums |
601ae28f76c5fdc524d836a40962f1931974501790bf97eaedd6f3b1134c03bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","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.10.0-py3-none-any.whl
| Download URL | pydantic_market_data-0.10.0-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a4e245ffc69058983c4df1fa5158dd0b1c967f5ed1f8ffcc5b72faf7c9ceca28
|
|
BLAKE2b-256 checksum How to use checksums |
3853332198c4edefc1f68b2299e60948ee17d244771ac32babf51271af6990e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","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}
|
Security for pydantic-market-data 0.10.0
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.