Skip to main content

Shared models and interfaces for finance datasources

Project description

pydantic-market-data

PyPI version License: MIT CI Status

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, History, SecurityCriteria, Symbol

# Security Definition
s = Security(
    symbol="AAPL",
    name="Apple Inc.",
    exchange="NASDAQ",
    currency="USD",
    asset_class="Equity",
    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 Criteria
criteria = SecurityCriteria(
    symbol="AAPL",
    asset_class="Equity",
    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, Security, History, Symbol, HistoryPeriod

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

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

    def search(self, query: str) -> List[Security]:
        # 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 --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 --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.3.2.tar.gz (15.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.3.2-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydantic_market_data-0.3.2.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","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.3.2.tar.gz
Algorithm Hash digest
SHA256 7083fe0e73877994ab467f17e5741af5859952b484fb6187f3d260529399f7bd
MD5 dbdd4a1a84ff3e8fc1efc0b61974eb92
BLAKE2b-256 c00acfdcc9e25d93d5556e480bc87f0c8a01c905c5939f39dad7d9abd43aa42e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pydantic_market_data-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","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.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d31318746c9e91d7feef729ffe94f8d59a68a258857b6aa16aad7ce795f0dcba
MD5 7c028a85100a6e5c45e0970abb0f3438
BLAKE2b-256 9c64bb7cfb3e16a3d9da9babe224da40c23e461b0e78f88274b55d897125d92b

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