Skip to main content

Official Python SDK for the PLCs.ai API — interpret PLC code from your own tools.

Project description

plcsai — Python SDK for the PLCs.ai API

Interpret PLC code from your own tools. Official Python client for the PLCs.ai API. Zero third-party dependencies.

Install

pip install plcsai

Requires Python 3.8+.

Quickstart

from plcsai import Client

client = Client(api_key="plck_live_…")  # or set PLCS_API_KEY

result = client.interpret(
    project_id="prj_…",
    prompt="Why is the filler at line 2 not advancing past Starting?",
)
print(result.answer)
print(result.citations)
print(result.request_id)  # quote this in a support request

Streaming

for event in client.interpret_stream(project_id="prj_…", prompt="…"):
    if event.type == "token":
        print(event.text, end="", flush=True)
    elif event.type == "done":
        print("\nusage:", event.usage)

Conversations, analyses, ingest, embed tokens

conv = client.create_conversation("prj_…", name="Line 2 stoppage")
client.send_message(conv.conversation_id, "And why now?")

job = client.start_analysis("prj_…")
done = client.wait_for_analysis(job.analysis_id)

client.ingest_project(file_path="Conveyor.L5X")

token = client.mint_embed_token("prj_…")  # read-only, for the iframe

Projects: list, read source, live values

page = client.list_projects(limit=50)
for p in page.projects:
    print(p.project_id, p.name, p.vendor)

detail = client.get_project("prj_…")          # metadata + analysis_status

src = client.get_source("prj_…", format="scl")  # parsed | scl | ladder (needs code_read)
raw_bytes = client.download_source("prj_…")      # original L5X / ZIP bytes

values = client.get_hmi_values("prj_…")          # needs hmi_view; live=False when no DCA session
history = client.get_hmi_history("prj_…", tag="Motor1.Speed")

Exports (async): PLC file & PDF report

job = client.export_plc("prj_…")                 # or client.export_pdf(...)
done = client.wait_for_export(job.export_id)
artifact = client.download_export(done.export_id)  # L5X / ZIP / PDF bytes
open(done.filename, "wb").write(artifact)

Save a new version (code_write)

res = client.commit_version("prj_…", file_path="Conveyor_edited.L5X")
print(res.resolution, res.version_id)  # add_version, or identical_file (no-op)

Generate code (ai_generate — proposes, never deploys)

proposal = client.generate("prj_…", "Add a 5-second start-up delay timer.")
print(proposal.generated_code)
for block in proposal.code_blocks:
    print(block.language, block.content)
# To persist, commit the edited file via client.commit_version(...) (code_write).

What the client handles for you

  • Auth — sends Authorization: Bearer … on every request.
  • Idempotency — auto-generates a stable Idempotency-Key per write (reused across retries).
  • Retries — backs off and retries only on retryable errors, respecting Retry-After.
  • Streaming — parses SSE into typed StreamEvents.
  • request_id — surfaced on every result.

Errors

Non-2xx responses raise plcsai.ApiError with .status_code, .error, .user_message, .suggested_action, .is_retryable, and .request_id.

Development

pip install -e '.[dev]'
pytest

Releasing (maintainers)

plcsai is published to PyPI. Bump version in pyproject.toml, then:

python -m build
python -m twine upload dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plcsai-1.1.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plcsai-1.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file plcsai-1.1.0.tar.gz.

File metadata

  • Download URL: plcsai-1.1.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for plcsai-1.1.0.tar.gz
Algorithm Hash digest
SHA256 cffc6b54c584765315fceb5987a525e60a58ae8c937d2e11ea90e52e77dc6435
MD5 9898881777e106b57de07e0853b1484a
BLAKE2b-256 6db7b6ad9b8c434873b0121774294eb64fcebf2132dafe0cc8ec7d866dbdd463

See more details on using hashes here.

File details

Details for the file plcsai-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: plcsai-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for plcsai-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 226c556f05f0653f4cbf671c32cca9a8cb447455dd2b4dfb74ca99b8492ba7f0
MD5 36a4fe2c73bef9a0650519719acb75cc
BLAKE2b-256 2fe69b491f37f4e9dfde85947c560579c2cc1efe8f083cbc25a1f3cdc5e41ac3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page