Skip to main content

Marketstack Python Client

A modern, fully-typed Python client for the Marketstack API (v2). Built on top of httpx and pydantic, this client offers high performance, strict type validation, and an elegant fluent API interface.


Features

  • Modern Python Support: Optimized for Python >= 3.10.
  • Fully Typed Requests & Responses: Leverages Pydantic v2 and PEP 692 Unpack for complete autocomplete, editor hints, and runtime validation.
  • Fluent & Hierarchical API: Easily access nested endpoints (e.g., client.tickers("AAPL").eod.list()).
  • Comprehensive Coverage: Supports 25+ namespaces covering end-of-day (EOD) data, intraday, tickers, stock exchanges, stock splits, dividends, ETFs, indices, currencies, bonds, commodities, company fundamentals, and more.

Installation

Install the package via pip:

pip install marketstack-python-client

Or using uv:

uv add marketstack-python-client

Quick Start

To use the client, you will need a Marketstack API key. Get one by registering at marketstack.com.

import os
from marketstack import Marketstack

# Initialize the client with your access key
client = Marketstack(api_key=os.environ["MARKETSTACK_API_KEY"])

# 1. Fetch generic End-of-Day (EOD) stock data
eod_data = client.eod.list(symbols="AAPL,MSFT")
for bar in eod_data.data:
    print(f"{bar.symbol} closed at {bar.close} on {bar.date}")

# 2. Access Ticker-specific data using the fluent API
aapl_ticker = client.tickers("AAPL").get()
print(f"Name: {aapl_ticker.name}, Stock Exchange: {aapl_ticker.stock_exchange.name}")

# Fetch EOD prices specifically for AAPL
aapl_eod = client.tickers("AAPL").eod.list(limit=10)
for bar in aapl_eod.data:
    print(f"AAPL Close: {bar.close}")

# 3. Access Stock Exchange specific tickers and EOD data
nasdaq_eod = client.exchanges("XNAS").eod.list(symbols="AAPL", limit=5)
print(f"Fetched {len(nasdaq_eod.data)} records from NASDAQ")

Client Namespaces & API Coverage

The Marketstack client provides dedicated namespaces mapping to the various endpoints of the Marketstack API.

1. Tickers (Fluent API)

Interact with a specific ticker symbol.

ticker = client.tickers("AAPL")

ticker.get()                      # Basic ticker information
ticker.eod.list()                 # End-of-Day historical data
ticker.eod.latest()               # Latest End-of-Day bar
ticker.eod.for_a_date("2023-10-27") # End-of-Day bar for a specific date
ticker.intraday.list()            # Intraday / Real-time data
ticker.intraday.latest()          # Latest intraday data
ticker.intraday.for_a_date("2023-10-27")
ticker.splits.list()              # Split history
ticker.dividends.list()           # Dividend history

2. Stock Exchanges (Fluent API)

Interact with stock exchanges.

exchange = client.exchanges("XNAS")

exchange.get()                    # Basic exchange info
exchange.tickers.list()           # All tickers listed on this exchange
exchange.eod.list(symbols="AAPL") # EOD data for a ticker on this exchange
exchange.intraday.list(symbols="AAPL") # Intraday data for a ticker on this exchange

3. End-of-Day (EOD) & Intraday Market Data

Retrieve general EOD and Intraday datasets.

# General EOD endpoints
client.eod.list(symbols="AAPL", date_from="2023-01-01")
client.eod.latest(symbols="AAPL")
client.eod.for_a_date(date="2023-10-27", symbols="AAPL")

# General Intraday endpoints
client.intraday.list(symbols="AAPL")
client.intraday.latest(symbols="AAPL")
client.intraday.for_a_date(date="2023-10-27", symbols="AAPL")

4. Other Specialized Namespaces

The client supports many other endpoints depending on your Marketstack subscription tier:

  • Dividends & Splits:
    • client.dividends.list(symbols="AAPL")
    • client.splits.list(symbols="AAPL")
  • Currencies & Timezones:
    • client.currencies.list()
    • client.timezones.list()
  • Bonds & Index Info:
    • client.bondlist.list(country="US")
    • client.bond.get(country="US")
    • client.indexlist.list()
    • client.indexinfo.get(index="SPX")
  • ETFs:
    • client.etflist.list(ticker="SPY")
    • client.etfholdings.get(ticker="PRSVX")
  • Company Fundamentals (Requires Enterprise/Tier Plan):
    • client.company_facts.get(cik_code="0000320193")
    • client.companyname.get(cik_code="0000320193")
    • client.companyratings.get(ticker="AAPL")
    • client.concept.get_accounts_payable(cik_code="0000320193")

Development

We use uv for dependency management and workspace workflows.

Prerequisites

  • Python 3.10 or higher
  • uv package manager

Setup

Clone the repository and install the dependencies:

uv sync

Running Tests

This project uses pytest for unit and integration testing.

# Run all unit tests
uv run pytest -v

To run the integration tests against the live Marketstack API, make sure to set the MARKETSTACK_API_KEY environment variable in your .env or current session. Note that some tests require higher-tier plans and are marked to be skipped if your API key lacks access.

export MARKETSTACK_API_KEY="your_api_key_here"
uv run pytest tests/test_integration.py

License

This project is licensed under the MIT License. See individual files or package settings for more details.

Metadata

Release files for marketstack-python-client 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for marketstack-python-client 1.0.1
File Size Uploaded
marketstack_python_client-1.0.1.tar.gz 40.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for marketstack-python-client 1.0.1
File Interpreter ABI Platform
marketstack_python_client-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 81.8 kB

Release files / marketstack_python_client-1.0.1.tar.gz

Download URL marketstack_python_client-1.0.1.tar.gz
Size 40.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fbb663f8ceb92a8d2c26958da7a81323418b8e6a05bf30bf644e8fc9b89cda19
BLAKE2b-256 checksum
How to use checksums
ab80b2789a76452690b0d29c89a33b16d6225b86a6eac4b2b172237b5a826078
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / marketstack_python_client-1.0.1-py3-none-any.whl

Download URL marketstack_python_client-1.0.1-py3-none-any.whl
Size 41.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4cf31fa5f6c5ab02568b4c09e89b1b54acdcc8729625fd2919d21b989cd27226
BLAKE2b-256 checksum
How to use checksums
8871f27e58d04ebd3a8d94aca3bfa8593b5c0deeb3e36ac23cc8e685de1bbbe6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page