blocksize-agent-tools 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ """Blocksize market data tools for agent frameworks.
2
+
3
+ The core client has no dependencies. Framework tools live in submodules that import
4
+ their framework only when used: ``blocksize_agent_tools.langchain``,
5
+ ``blocksize_agent_tools.llamaindex`` and ``blocksize_agent_tools.openai_agents``.
6
+ """
7
+
8
+ from .client import BlocksizeHTTPClient, BlocksizePaymentRequired
9
+
10
+ __all__ = ["BlocksizeHTTPClient", "BlocksizePaymentRequired"]
11
+ __version__ = "0.1.0"
@@ -0,0 +1,83 @@
1
+ """Small dependency-free Blocksize HTTP client shared by every framework integration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from collections.abc import Callable
7
+ from typing import Any
8
+ from urllib.error import HTTPError
9
+ from urllib.parse import quote, urlencode
10
+ from urllib.request import Request, urlopen
11
+
12
+
13
+ class BlocksizePaymentRequired(RuntimeError):
14
+ """Raised when Blocksize returns a valid x402 payment challenge."""
15
+
16
+ def __init__(self, message: str, *, payment_required: str | None = None) -> None:
17
+ super().__init__(message)
18
+ self.payment_required = payment_required
19
+
20
+
21
+ class BlocksizeHTTPClient:
22
+ """Read-only Blocksize HTTP client for agent framework tools."""
23
+
24
+ def __init__(
25
+ self,
26
+ agent_id: str,
27
+ *,
28
+ base_url: str = "https://mcp.blocksize.info",
29
+ timeout: float = 20.0,
30
+ opener: Callable[..., Any] = urlopen,
31
+ ) -> None:
32
+ clean_agent_id = agent_id.strip()
33
+ if len(clean_agent_id) < 8:
34
+ raise ValueError("agent_id must be a stable identifier with at least 8 characters")
35
+ self.agent_id = clean_agent_id
36
+ self.base_url = base_url.rstrip("/")
37
+ self.timeout = timeout
38
+ self._opener = opener
39
+
40
+ @staticmethod
41
+ def _instrument(value: str) -> str:
42
+ clean = value.strip().lower().replace("_", "-").replace("/", "-")
43
+ if not clean or any(character not in "abcdefghijklmnopqrstuvwxyz0123456789-" for character in clean):
44
+ raise ValueError("instrument must contain only letters, numbers, slash, underscore, or hyphen")
45
+ return quote(clean, safe="-")
46
+
47
+ def _get(self, path: str, query: dict[str, str] | None = None) -> dict[str, Any]:
48
+ suffix = f"?{urlencode(query)}" if query else ""
49
+ request = Request(
50
+ f"{self.base_url}{path}{suffix}",
51
+ headers={
52
+ "Accept": "application/json",
53
+ "X-Agent-ID": self.agent_id,
54
+ "User-Agent": "blocksize-framework-integration/1.0",
55
+ },
56
+ method="GET",
57
+ )
58
+ try:
59
+ with self._opener(request, timeout=self.timeout) as response:
60
+ payload = json.loads(response.read().decode("utf-8"))
61
+ except HTTPError as exc:
62
+ if exc.code == 402:
63
+ raise BlocksizePaymentRequired(
64
+ "Blocksize starter credits are unavailable or exhausted; complete the returned x402 challenge.",
65
+ payment_required=exc.headers.get("PAYMENT-REQUIRED"),
66
+ ) from exc
67
+ body = exc.read().decode("utf-8", errors="replace")[:800]
68
+ raise RuntimeError(f"Blocksize returned HTTP {exc.code}: {body}") from exc
69
+ if not isinstance(payload, dict):
70
+ raise RuntimeError("Blocksize returned a non-object JSON response")
71
+ return payload
72
+
73
+ def search(self, query: str, *, asset_class: str | None = None) -> dict[str, Any]:
74
+ params = {"q": query.strip()}
75
+ if asset_class:
76
+ params["asset_class"] = asset_class.strip().lower()
77
+ return self._get("/v1/search", params)
78
+
79
+ def get_vwap(self, pair: str) -> dict[str, Any]:
80
+ return self._get(f"/v1/vwap/{self._instrument(pair)}")
81
+
82
+ def get_bid_ask(self, pair: str) -> dict[str, Any]:
83
+ return self._get(f"/v1/bidask/{self._instrument(pair)}")
@@ -0,0 +1,28 @@
1
+ """LangChain tools backed by Blocksize production market data."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+
7
+ from langchain.tools import tool
8
+
9
+ from .client import BlocksizeHTTPClient
10
+
11
+
12
+ def build_blocksize_tools(agent_id: str | None = None) -> list:
13
+ """Return the Blocksize VWAP and bid/ask tools for a LangChain agent."""
14
+ client = BlocksizeHTTPClient(
15
+ agent_id or os.environ.get("BLOCKSIZE_AGENT_ID", "langchain-blocksize-agent")
16
+ )
17
+
18
+ @tool
19
+ def blocksize_vwap(pair: str) -> dict:
20
+ """Get the latest Blocksize VWAP for a pair such as BTC-USD, including timestamp and citation metadata."""
21
+ return client.get_vwap(pair)
22
+
23
+ @tool
24
+ def blocksize_bid_ask(pair: str) -> dict:
25
+ """Get the latest Blocksize bid/ask for a supported crypto or equity instrument."""
26
+ return client.get_bid_ask(pair)
27
+
28
+ return [blocksize_vwap, blocksize_bid_ask]
@@ -0,0 +1,29 @@
1
+ """LlamaIndex FunctionTool wrappers for Blocksize market data."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+
7
+ from llama_index.core.tools import FunctionTool
8
+
9
+ from .client import BlocksizeHTTPClient
10
+
11
+
12
+ def build_blocksize_tools(agent_id: str | None = None) -> list[FunctionTool]:
13
+ """Return the Blocksize VWAP and bid/ask tools for a LlamaIndex agent."""
14
+ client = BlocksizeHTTPClient(
15
+ agent_id or os.environ.get("BLOCKSIZE_AGENT_ID", "llamaindex-blocksize-agent")
16
+ )
17
+
18
+ def blocksize_vwap(pair: str) -> dict:
19
+ """Return Blocksize VWAP, source timestamp, methodology, and citation metadata."""
20
+ return client.get_vwap(pair)
21
+
22
+ def blocksize_bid_ask(pair: str) -> dict:
23
+ """Return Blocksize bid/ask data for a supported crypto or equity instrument."""
24
+ return client.get_bid_ask(pair)
25
+
26
+ return [
27
+ FunctionTool.from_defaults(fn=blocksize_vwap),
28
+ FunctionTool.from_defaults(fn=blocksize_bid_ask),
29
+ ]
@@ -0,0 +1,36 @@
1
+ """OpenAI Agents SDK function tools for Blocksize production data."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+
7
+ from agents import function_tool
8
+
9
+ from .client import BlocksizeHTTPClient
10
+
11
+
12
+ def build_blocksize_tools(agent_id: str | None = None) -> list:
13
+ """Return the Blocksize VWAP and bid/ask tools for an OpenAI Agents SDK agent."""
14
+ client = BlocksizeHTTPClient(
15
+ agent_id or os.environ.get("BLOCKSIZE_AGENT_ID", "openai-agents-blocksize")
16
+ )
17
+
18
+ @function_tool
19
+ def blocksize_vwap(pair: str) -> dict:
20
+ """Get a live Blocksize VWAP with its source timestamp and citation metadata.
21
+
22
+ Args:
23
+ pair: Instrument such as BTC-USD.
24
+ """
25
+ return client.get_vwap(pair)
26
+
27
+ @function_tool
28
+ def blocksize_bid_ask(pair: str) -> dict:
29
+ """Get a live Blocksize bid/ask for a supported crypto or equity instrument.
30
+
31
+ Args:
32
+ pair: Instrument such as ETH-USD or AAPL.
33
+ """
34
+ return client.get_bid_ask(pair)
35
+
36
+ return [blocksize_vwap, blocksize_bid_ask]
@@ -0,0 +1,73 @@
1
+ Metadata-Version: 2.5
2
+ Name: blocksize-agent-tools
3
+ Version: 0.1.0
4
+ Summary: Blocksize live market data tools for LangChain, LlamaIndex and OpenAI Agents SDK agents, with x402 pay-per-call.
5
+ Project-URL: Homepage, https://mcp.blocksize.info
6
+ Project-URL: Source, https://github.com/jf-cmyk/agentic-payments/tree/main/integrations/python
7
+ Author: Blocksize Capital
8
+ License-Expression: MIT
9
+ Keywords: ai-agents,blocksize,langchain,llamaindex,market-data,openai-agents,x402
10
+ Requires-Python: >=3.10
11
+ Provides-Extra: langchain
12
+ Requires-Dist: langchain>=1.3.14; extra == 'langchain'
13
+ Provides-Extra: llamaindex
14
+ Requires-Dist: llama-index-core>=0.14.23; extra == 'llamaindex'
15
+ Provides-Extra: openai-agents
16
+ Requires-Dist: openai-agents>=0.18.3; extra == 'openai-agents'
17
+ Description-Content-Type: text/markdown
18
+
19
+ # blocksize-agent-tools
20
+
21
+ Blocksize live market data (VWAP and bid/ask for crypto and equities) as read-only tools for Python agent frameworks. Calls go to [https://mcp.blocksize.info](https://mcp.blocksize.info): a stable agent ID gets the standard starter allowance, after that each call is paid per request through x402. Responses keep Blocksize timestamps and citation metadata.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install blocksize-agent-tools # core client only, no dependencies
27
+ pip install "blocksize-agent-tools[langchain]"
28
+ pip install "blocksize-agent-tools[llamaindex]"
29
+ pip install "blocksize-agent-tools[openai-agents]"
30
+ ```
31
+
32
+ Set a stable agent ID (at least 8 characters) with `BLOCKSIZE_AGENT_ID`, or pass `agent_id=` to any builder.
33
+
34
+ ## Core client
35
+
36
+ ```python
37
+ from blocksize_agent_tools import BlocksizeHTTPClient, BlocksizePaymentRequired
38
+
39
+ client = BlocksizeHTTPClient("my-research-agent-01")
40
+ try:
41
+ print(client.get_vwap("BTC-USD"))
42
+ except BlocksizePaymentRequired as exc:
43
+ print("x402 challenge:", exc.payment_required)
44
+ ```
45
+
46
+ ## LangChain
47
+
48
+ ```python
49
+ from langchain.agents import create_agent
50
+ from blocksize_agent_tools.langchain import build_blocksize_tools
51
+
52
+ agent = create_agent("openai:gpt-5", tools=build_blocksize_tools("my-research-agent-01"))
53
+ ```
54
+
55
+ ## LlamaIndex
56
+
57
+ ```python
58
+ from llama_index.core.agent.workflow import FunctionAgent
59
+ from blocksize_agent_tools.llamaindex import build_blocksize_tools
60
+
61
+ agent = FunctionAgent(tools=build_blocksize_tools("my-research-agent-01"), llm=llm)
62
+ ```
63
+
64
+ ## OpenAI Agents SDK
65
+
66
+ ```python
67
+ from agents import Agent
68
+ from blocksize_agent_tools.openai_agents import build_blocksize_tools
69
+
70
+ agent = Agent(name="Markets", tools=build_blocksize_tools("my-research-agent-01"))
71
+ ```
72
+
73
+ Docs and pricing: [https://mcp.blocksize.info](https://mcp.blocksize.info)
@@ -0,0 +1,8 @@
1
+ blocksize_agent_tools/__init__.py,sha256=fwfO9e-HtHxz6Prm_ZThhhn-6PHLaSZ_kpNbBLeaInI,445
2
+ blocksize_agent_tools/client.py,sha256=Wc7pxTNVBC2M8DT9VWrsXsa6JrAhgVpDbOQLhgh-nC4,3368
3
+ blocksize_agent_tools/langchain.py,sha256=CZlMdBp2u3cOUzA05MVbjfTf8Bmn-bOVHigWMatpdQ8,900
4
+ blocksize_agent_tools/llamaindex.py,sha256=8i55NL0zCamUNcJK9ydk2zm3LO6MuuIXRUtrn9ay_RI,969
5
+ blocksize_agent_tools/openai_agents.py,sha256=bOXPTbQ9qtSO0CHrYaZmLWWuPIwAX38c7vahYnzP2ME,1047
6
+ blocksize_agent_tools-0.1.0.dist-info/METADATA,sha256=qXezGMrIWH0ZjMB5IRjlJ2zcstsjy1SY1ysLeM2BXak,2605
7
+ blocksize_agent_tools-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
8
+ blocksize_agent_tools-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any