Skip to content
Lexicor Docs

SDKs

Python SDK

lexicor-client is the official Python client for the Lexicor HTTP API. It mirrors the REST endpoints with typed methods, automatic retries, and rate-limit handling.

Install

bash
pip install lexicor-client

Quick start

Construct a client with your base URL and API key, then parse a directive and run a round-trip:

Quick start
from lexicor_client import LexicorClient

client = LexicorClient("https://api.lexicor.dev", api_key="lx-your-key")

ing = client.ingest("Schedule a follow-up with the team next Tuesday.", build_packet=False)
assert ing["parsed"]
my_graph = ing["intent_graph"]

normalized = client.normalize(my_graph)
result = client.roundtrip(my_graph)
comparison = client.compare(my_graph, normalized)

Ingress and LM fallback

Template ingress is the default. Enable model-backed parsing when no template matches (the server must be configured for it):

LM fallback
client.ingest(
    "Some unusual directive…",
    lm_fallback=True,
    build_packet=True,
    render_strategy="ascii_compact",
)

Negotiation and full packets

Advertise capabilities, confirm the session, then build and decode transport packets with packet_build / packet_decode (/v1/packet/build and /v1/packet/decode):

Negotiation and packets
agent_id = "my-remote-agent"
client.negotiate_advertise(
    agent_id,
    supported_codecs=["lexicor-line-v1"],
    supported_symbol_tables=["core-sym-1"],
    supported_fidelity_tiers=[0, 1, 2, 3],
)
offer = client.negotiate_offer("sess-001", agent_id)
if offer["type"] != "offer":
    raise RuntimeError(offer.get("reason", "negotiation failed"))
contract = offer["contract"]
client.negotiate_confirm("sess-001")
contract["session_id"] = "sess-001"

built = client.packet_build(
    my_graph,
    session=contract,
    render_strategy="ascii_compact",
    payload_mode="semantic_transport",
)
decoded = client.packet_decode(built["packet"])
graph = decoded["intent_graph"]
Custom transport

Pass transport= an httpx.BaseTransport when constructing LexicorClient for custom HTTP behavior (proxies, test doubles).

Features

  • Automatic retry with exponential backoff.
  • Rate-limit handling (429 with Retry-After).
  • Context-manager support and type hints throughout.

Endpoint-level detail lives in the API reference.

Patent pending — Appl. No. 64/042,667

© 2026 Lexicor. All rights reserved.