Skip to main content

Shared models and interfaces for finance datasources

Project description

pydantic-market-data

Shared Pydantic models and interfaces for financial data sources. Defines a standard contract (DataSource) and data structures (OHLCV, Symbol, History) to interoperability between finance packages.

Installation

pip install pydantic-market-data

Usage

Models

Standardized data models for financial entities.

from pydantic_market_data.models import Symbol, OHLCV, History, SecurityCriteria, Ticker

# Symbol Definition
s = Symbol(
    ticker="AAPL",
    name="Apple Inc.",
    exchange="NASDAQ",
    currency="USD"
)

# 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 Criteria
criteria = SecurityCriteria(
    symbol="AAPL",
    target_date="2023-12-01" # Coerced to FlexibleDate
)

Protocol

Implement the DataSource protocol to create compatible data providers.

from typing import Optional, List
from pydantic_market_data.interfaces import DataSource
from pydantic_market_data.models import SecurityCriteria, Symbol, History, Ticker, HistoryPeriod

class MySource(DataSource):
    def resolve(self, criteria: SecurityCriteria) -> Optional[Symbol]:
        # Implementation...
        pass

    def history(self, ticker: Ticker | str, period: HistoryPeriod = HistoryPeriod.MO1) -> History:
        # Implementation...
        pass

    def search(self, query: str) -> List[Symbol]:
        # Implementation...
        pass

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

class MyCliSettings(BaseSettings):
    search: SearchArgs

    @classmethod
    def settings_customise_sources(cls, settings_cls, **kwargs):
        return (PatchedCliSettingsSource(settings_cls),)

# Usage:
# my-tool search --ticker 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 --vv to -vv.
  • JSON Schema: Adds a --schema flag to output the interface definition.
  • Metavars: Custom types (SYMBOL, ISIN, etc.) provide descriptive help labels.

License

MIT

Project details


Download files

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

Source Distribution

pydantic_market_data-0.1.13.tar.gz (90.6 kB view details)

Uploaded Source

Built Distribution

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

pydantic_market_data-0.1.13-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_market_data-0.1.13.tar.gz.

File metadata

  • Download URL: pydantic_market_data-0.1.13.tar.gz
  • Upload date:
  • Size: 90.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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}

File hashes

Hashes for pydantic_market_data-0.1.13.tar.gz
Algorithm Hash digest
SHA256 5de56911939c97bdade3c449b3ec92cc85c7bcced7c65bb605fde01ace7d99de
MD5 5b35e405707e98dc804fafa7e773c7f3
BLAKE2b-256 577b69b36398785b52b73a8d12a015aa39bcfaeb06b321acf123620f493ea23f

See more details on using hashes here.

File details

Details for the file pydantic_market_data-0.1.13-py3-none-any.whl.

File metadata

  • Download URL: pydantic_market_data-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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}

File hashes

Hashes for pydantic_market_data-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 f86fbd8d7aedc0be1d8f1fd1f38e64ef31d8d7af31426552549cb69cea976956
MD5 6fc13415672f225202bce39a4117a0b0
BLAKE2b-256 a8b76022d36d97f21294ddbe4dc54e07b218ab39d1fb313be4970983146602f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page