Skip to main content

Lamatic Python SDK

Python SDK for Lamatic.

Requires Python 3.10+

Installation

pip install lamatic

Install from source

git clone https://github.com/Lamatic/Lamatic-Python-SDK.git
cd Lamatic-Python-SDK
pip install -e .

For development (includes test dependencies)

pip install -e ".[dev]"

Quick Start

from lamatic import Lamatic

lamatic = Lamatic(
    endpoint="https://your-project.lamatic.ai/api/graphql",
    project_id="your-project-id",
    api_key="your-api-key",
)

# Execute a flow (sync)
response = lamatic.execute_flow("flow-id", {"prompt": "Hello!"})
print(response.status)  # "success"
print(response.result)

# Poll status
response = lamatic.check_status("request-id", poll_interval=5, poll_timeout=120)

Async Usage

import asyncio
from lamatic import Lamatic

lamatic = Lamatic(
    endpoint="https://your-project.lamatic.ai/api/graphql",
    project_id="your-project-id",
    api_key="your-api-key",
)

async def main():
    response = await lamatic.async_execute_flow("flow-id", {"prompt": "Hello!"})
    print(response.status)
    print(response.result)

asyncio.run(main())

Token Streaming

execute_flow_token_stream runs a flow and yields its LLM/RAG output one token at a time, so you can render text as it is generated instead of waiting for the whole flow to finish.

for event in lamatic.execute_flow_token_stream("flow-id", {"sampleInput": "Hello"}):
    if event.type == "token":
        print(event.token, end="", flush=True)   # one text delta
    elif event.type == "node":
        print(f"\n[{event.node_id}] finished", event.output)
    elif event.type == "final":
        print("\nFull text:", event.text)
        print("Flow result:", event.result)
    elif event.type == "error":
        print("\nStream failed:", event.message)

An async variant, async_execute_flow_token_stream, works the same way with async for.

Events

type Fields Emitted when
token token, node_id, raw An LLM or RAG node produces a text delta
node node_id, output, raw Any node finishes; output is its full output
final result, text, text_by_node, raw The flow finishes — always the last event of a successful stream
error message, node_id, raw Execution failed; the stream ends if the failure was fatal

Events are dataclasses, so match event: with LamaticTokenEventToken() etc. works too. Every event carries raw, the untouched server frame, for fields the typed event does not expose — such as _meta on a node event, which holds token counts and cost:

if event.type == "node" and event.raw.get("data", {}).get("_meta"):
    meta = event.raw["data"]["_meta"]
    print(f"{meta['model_name']}: {meta['total_tokens']} tokens, ${meta['total_cost']}")

Reading the generated text

Use final.text — every token concatenated in arrival order. Don't read generatedResponse off a node's output instead:

  • A flow's final result contains only what its response node was configured to return, which often does not include the generated text at all.
  • The platform currently returns a streaming node's generatedResponse with its content duplicated. final.text is built from the deltas, so it is correct.

For a flow with more than one streaming node, final.text_by_node keys the text by node ID.

Only LLM and RAG nodes emit token events. Every other node reports once, as a single node event when it completes.

Errors and cancelling

Failures (bad credentials, network errors, a stream that closes before the flow finishes) arrive as an error event rather than an exception.

To stop early, break out of the loop. The generator is closed and the connection released. In async code, cancelling the consuming task does the same.

async def main():
    async for event in lamatic.async_execute_flow_token_stream("flow-id", {"sampleInput": "Write a long story"}):
        if event.type == "token":
            print(event.token, end="", flush=True)

Authentication

Either api_key or access_token is required:

# API key auth
lamatic = Lamatic(endpoint=..., project_id=..., api_key="your-api-key")

# Access token auth
lamatic = Lamatic(endpoint=..., project_id=..., access_token="your-token")

# Refresh token at runtime
lamatic.update_access_token("new-token")

Metadata

Release files for lamatic 0.2.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 lamatic 0.2.0
File Size Uploaded Provenance Actions
lamatic-0.2.0.tar.gz 11.0 kB Without provenance Details for lamatic-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lamatic 0.2.0
File Interpreter ABI Platform Actions
lamatic-0.2.0-py3-none-any.whl Python 3 none any Details for lamatic-0.2.0-py3-none-any.whl

Total release size: 21.4 kB

Release files / lamatic-0.2.0.tar.gz

Download URL lamatic-0.2.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b019e3f6d1762fc42dde9b4a0147e109632fb152fc073acffdb89af94e7b2c88
BLAKE2b-256 checksum
How to use checksums
3544ed10c014c7a7e17c4d30f0948a84be6f69b5e3bb141c105bde44c1a032e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / lamatic-0.2.0-py3-none-any.whl

Download URL lamatic-0.2.0-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ef06422de8ad74d27aa659dfd8327e1dd93ca98a9b149cac1068109714ea824
BLAKE2b-256 checksum
How to use checksums
56710a546a38f302da32d795f3467a3014fc0ef81b93a4c035c1e8f36e499e22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for lamatic 0.2.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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