Skip to main content

langchain-aperiodic

PyPI CI License: MIT

LangChain tools for Aperiodic, point-in-time market data for perpetual futures on Binance, OKX and Hyperliquid.

Aperiodic covers crypto perpetuals and perpetuals on tokenized stocks (TSLA, NVDA, AAPL and others), indices (the S&P 500 through Hyperliquid HIP-3 markets) and commodities (gold, oil), delisted contracts included. Its datasets are OHLCV bars, funding rate, open interest and other derivatives data, and order flow and liquidity (L1/L2 order book) metrics. This package wraps the aperiodic Python SDK.

Installation

pip install -U langchain-aperiodic

Requires Python 3.11 or later (as do aperiodic and langchain-core 1.x).

Authentication

Make an API key at aperiodic.io/home/api and set it:

export APERIODIC_API_KEY="your-api-key"

or pass api_key="..." to a tool or the toolkit. A key saved on the machine by aperiodic.login() is also picked up. A free account key covers a fixed sample of markets and dates; see aperiodic.io/pricing.

Without a key the tools use Aperiodic's public preview, which serves only a small fixed sample (listed at aperiodic.io/catalog#preview); other requests come back as an error message the model can read.

Tools

Tool name Class Wraps What it returns
aperiodic_symbol_search AperiodicSymbolSearch aperiodic.get_symbols The symbol ids of an asset's perpetuals on each venue, with the first and last day of data
aperiodic_ohlcv AperiodicOHLCV aperiodic.get_ohlcv OHLCV bars: the range as one bar (open, high, low, close, change, volume) and the latest bars
aperiodic_derivatives AperiodicDerivatives aperiodic.get_derivative_metrics funding, open_interest, basis or derivative_price (last, mark and index prices)
aperiodic_metrics AperiodicMetrics aperiodic.get_metrics Order flow, trade size, impact, slippage, VWAP/TWAP, range, returns, ticks, runs, and L1/L2 order book price, imbalance and liquidity

AperiodicToolkit().get_tools() returns all four.

Symbols are Atlas ids: perpetual-BTC-USDT:USDT on binance-futures and okx-perps, perpetual-BTC-USDC:USDC on hyperliquid-perps, and perpetual-XYZ:TSLA-USDC:USDC for a Hyperliquid HIP-3 market (the part before the colon names the market's dex). The tool descriptions tell the model this, and to call aperiodic_symbol_search when it is unsure.

The data tools take exchange, symbol, start_date and end_date (UTC days, inclusive), interval (1m to 1d, default 1h; 15s and 30s are not on every plan), timestamp (exchange for venue times, true for when the data reached Aperiodic) and last_n (rows to include, at most 50). aperiodic_derivatives and aperiodic_metrics also take metric and an optional list of columns.

Quickstart: an agent

from langchain.agents import create_agent

from langchain_aperiodic import AperiodicToolkit

tools = AperiodicToolkit().get_tools()

# Any chat model that supports tool calling, as "provider:model"
# (pip install "langchain[anthropic]", "langchain[openai]", ...).
agent = create_agent(model="anthropic:claude-sonnet-4-6", tools=tools)

result = agent.invoke(
    {
        "messages": [
            {
                "role": "user",
                "content": "Which venues list a TSLA perpetual, and how did the "
                "Hyperliquid one trade in October 2026?",
            }
        ]
    }
)
print(result["messages"][-1].content)

Without an API key

The public preview includes the Binance BTC-USDT perpetual at 5-minute bars for May 2025, so this runs with no key:

from langchain_aperiodic import AperiodicOHLCV, AperiodicSymbolSearch

ohlcv = AperiodicOHLCV()
print(
    ohlcv.invoke(
        {
            "exchange": "binance-futures",
            "symbol": "perpetual-BTC-USDT:USDT",
            "interval": "5m",
            "start_date": "2025-05-01",
            "end_date": "2025-05-31",
            "last_n": 2,
        }
    )
)

# Symbol search works without a key too: it reads the public coverage listing.
print(AperiodicSymbolSearch().invoke({"query": "NVDA"}))

The OHLCV call returns (formatted here; the tool returns compact JSON):

{
  "exchange": "binance-futures",
  "symbol": "perpetual-BTC-USDT:USDT",
  "dataset": "ohlcv",
  "interval": "5m",
  "timestamp": "exchange",
  "start_date": "2025-05-01",
  "end_date": "2025-05-31",
  "access": "public preview (no API key)",
  "rows": 8928,
  "first_time": "2025-05-01 00:00",
  "last_time": "2025-05-31 23:55",
  "time_zone": "UTC, start of each interval",
  "period": {
    "open": 94125.2,
    "high": 111959.5,
    "low": 93327.0,
    "close": 104544.7,
    "change_pct": 11.06983,
    "volume": 5650406.0,
    "volume_notional": 587505900000.0
  },
  "last_rows": {
    "columns": ["time", "open", "high", "low", "close", "volume", "volume_notional"],
    "rows": [
      ["2025-05-31 23:50", 104612.1, 104615.0, 104558.4, 104558.5, 85.636, 8956574.0],
      ["2025-05-31 23:55", 104558.4, 104562.8, 104536.3, 104544.7, 74.448, 7783346.0]
    ]
  },
  "rows_note": "Showing the last 2 of 8928 rows."
}

Output size

Each tool answers with a compact JSON summary sized for a model's context, never the whole series: the request, the row count, the first and last interval, per-column first/last/min/max/mean (for OHLCV, the range as one bar) and the last last_n rows (default 10, at most 50). Metric datasets have up to 36 columns; without columns the first 8 are summarized and the result lists the rest. Requests over max_bars intervals (default 250,000, about six months of 1-minute bars) are refused before anything is downloaded.

The full DataFrame

To keep the model's view small but work with every row in your code, construct a tool with response_format="content_and_artifact". Invoked with a tool call (as an agent does), it returns a ToolMessage whose content is the summary and whose artifact is the full pandas DataFrame:

from langchain_aperiodic import AperiodicMetrics

tool = AperiodicMetrics(response_format="content_and_artifact")
message = tool.invoke(
    {
        "name": tool.name,
        "id": "1",
        "type": "tool_call",
        "args": {
            "metric": "l1_liquidity",
            "exchange": "binance-futures",
            "symbol": "perpetual-BTC-USDT:USDT",
            "interval": "5m",
            "start_date": "2025-05-01",
            "end_date": "2025-05-31",
        },
    }
)
frame = message.artifact  # pandas DataFrame, 8928 rows

Or call the SDK directly:

from datetime import date

import aperiodic

frame = aperiodic.get_metrics(
    metric="l1_liquidity",
    exchange="binance-futures",
    symbol="perpetual-BTC-USDT:USDT",
    interval="5m",
    timestamp="exchange",
    start_date=date(2025, 5, 1),
    end_date=date(2025, 5, 31),
    output="pandas",
    preview=True,  # drop this when APERIODIC_API_KEY is set
)

Configuration

Argument On Default Meaning
api_key toolkit, every tool APERIODIC_API_KEY The API key, kept as a SecretStr and never logged
preview toolkit, every tool None None: use a key when one is found, else the public preview. True: always the preview. False: require a key
max_bars toolkit, data tools 250_000 Largest request, in intervals, a data tool accepts
cache_seconds AperiodicSymbolSearch 3600 How long symbol lists are reused
handle_tool_error every tool True API refusals (bad symbol, plan or preview limits, rate limits) are returned as the tool's output, so the agent can correct its call. False raises ToolException
response_format data tools "content" "content_and_artifact" adds the full DataFrame as ToolMessage.artifact

Invalid arguments (an unknown exchange, end_date before start_date) are also returned as text rather than raised.

Other ways to use Aperiodic from an agent

Aperiodic runs a remote MCP server at https://aperiodic.io/mcp, which LangChain agents can use through langchain-mcp-adapters.

Development

uv sync                    # dev dependencies: test, lint and typing groups
make test                  # unit tests, network disabled
make integration_tests     # live API, public preview; no key needed
make lint                  # ruff, ruff format --diff, mypy

Integration tests marked requires_key also run when APERIODIC_API_KEY is set. Skip all network tests with uv run pytest -m "not integration".

License

MIT. See LICENSE.

Metadata

Release files for langchain-aperiodic 0.1.0

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

Source distribution (sdist)

Source distribution for langchain-aperiodic 0.1.0
File Size Uploaded Provenance Actions
langchain_aperiodic-0.1.0.tar.gz 21.6 kB With provenance Details for langchain_aperiodic-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-aperiodic 0.1.0
File Interpreter ABI Platform Actions
langchain_aperiodic-0.1.0-py3-none-any.whl Python 3 none any Details for langchain_aperiodic-0.1.0-py3-none-any.whl

Total release size: 43.8 kB

Release files / langchain_aperiodic-0.1.0.tar.gz

Download URL langchain_aperiodic-0.1.0.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
def80411e2e491ecc692dc8d9b0552bd7042f49befb6877520c365ce7d29943d
BLAKE2b-256 checksum
How to use checksums
d0cf0f87871c12b846e95a796c18ab066d09527799d47715654e4fe7a70ca326
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / langchain_aperiodic-0.1.0-py3-none-any.whl

Download URL langchain_aperiodic-0.1.0-py3-none-any.whl
Size 22.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea3bb2281f6d55280c740b5c8f5c7ff7af2702d8636cf7c2d769f96db69bed39
BLAKE2b-256 checksum
How to use checksums
691425459d1c50d600af6541440e0c8f5036b67cd69a807c038894bf31c40da2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for langchain-aperiodic 0.1.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for langchain_aperiodic-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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