Skip to main content

Elektric Python SDK

Canonical documentation: Quickstart · AI coding agents · llms.txt

One provider-neutral Python interface for chat, media, Web, tools, state, jobs, and realtime.

The distribution is elektric-ai; the Python import remains elektric.

This is the official elektric-ai distribution. Do not substitute a similarly named distribution.

Install and configure

python -m pip install elektric-ai
from elektric import Elektric

with Elektric() as client:
    response = client.chat(
        message="Explain quantum computing simply.",
        user_id="user-123",
        conversation_id="thread-123",
    )
    print(response.message, response.request_id)

The production URL is built in; base_url is only needed for local or staged deployments. Native chat requires customer-defined user_id and conversation_id; the elektric-auto model is implicit. No provider key, provider name, or model is accepted. AI executions are never automatically retried.

Conversations

conversation = client.conversations.get(conversation_id="thread-123")
recent = client.conversations.list(user_id="user-123", limit=20)
client.conversations.delete(conversation_id="thread-123")

GET messages are chronological and cursor-paginated with message_cursor (default/max 100). LIST is newest-updated-first with opaque cursors (default 20, max 100). Deleting a Conversation does not delete Memory, Knowledge, or other Conversations; a later chat may recreate a fresh thread with the same external ID.

Memory management

Memory is durable user-specific information across Conversations and remains automatic during chat.

memories = client.memory.list(user_id="user-123")
card = client.memory.get(user_id="user-123", memory_id=memories.data[0].id)
client.memory.update(user_id="user-123", memory_id=card.id, summary="User prefers concise prose.")
client.memory.delete(user_id="user-123", memory_id=card.id)

Manual create is deferred; the certified updater owns stable conceptual keys and the 30-card/1,000-token profile limits. Delete deactivates active Memory immediately but does not erase source Conversations or History.

Async and streaming

from elektric import AsyncElektric

async with AsyncElektric() as client:
    response = await client.chat(message="Hello", user_id="user-123", conversation_id="async-123")
    async for event in client.chat_stream(
        message="Count to three", user_id="user-123", conversation_id="async-stream"
    ):
        if event.type == "content_delta":
            print(event.text, end="")

Sync streaming is the same iterator pattern without async. Closing a local stream or wait does not imply remote cancellation.

Web and tools

Set web=True and read response.sources. Tools use Elektric dictionaries with name, description, and input_schema; calls expose id, name, and parsed arguments. Execute them locally, then send the original user message followed by {"role": "tool", "tool_call_id": call["id"], "content": result}.

Files, embeddings, and media

Use files.upload/get/delete, assets.get/download/delete, embeddings.create, and the discoverable embedding_profiles alias. Media methods are audio.transcribe/speech, images.generate/edit, video.analyze/generate, and jobs.get/wait/cancel. Video generation returns an ElektricJob; stopping a local wait never cancels it.

Realtime

Realtime is intentionally async-only in Python:

async with await client.realtime.connect(input=["text"], output=["text"]) as session:
    await session.send_text("Hello")
    async for event in session:
        print(event.type, event.data)

Sessions also provide send_audio, commit_audio, interrupt, and close.

Errors and support

Catch ElektricError and inspect type, code, status_code, request_id, and safe details. Canonical subclasses include authentication, invalid-request, rate-limit, timeout, and service errors. Legacy billing, bad-request, and server subclasses remain compatible. Provider errors and secrets are never exposed or logged.

Python 3.10–3.12 metadata is supported. Both clients are context managers and should be closed. See Elektric documentation. The native SDK is recommended for the full platform; OpenAI compatibility is for quick migration of existing code.

Streaming Web sources

Pass web=True to synchronous or asynchronous chat_stream. A StreamEvent(type="source") carries an ElektricSource; source events may arrive before, during, or after content deltas and are de-duplicated by URL. The server sends finish before [DONE].

Knowledge management

Knowledge is project-level reference material used automatically when relevant. client.knowledge.add(file) accepts a path, bytes, or open binary file. Use list, get, and delete, and poll until status == "ready". Retry is deferred: delete and re-upload failed sources.

Download files

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

Source Distribution

elektric_ai-0.1.0.tar.gz (31.7 kB view details)

Uploaded Source

Built Distribution

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

elektric_ai-0.1.0-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file elektric_ai-0.1.0.tar.gz.

File metadata

  • Download URL: elektric_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 31.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for elektric_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa67ae8a579b4c8706cb143d24dbb25f7be874ecdf07bdcedf83d7b8a1cc4e81
MD5 2fbf493a6e570df426e0cea01569f8ac
BLAKE2b-256 ff9cd63d532a9dfb062cf8f369369f3831c1d2078bd067d284828d9837d67d81

See more details on using hashes here.

Provenance

The following attestation bundles were made for elektric_ai-0.1.0.tar.gz:

Publisher: publish-python.yml on realVasileios/electric

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file elektric_ai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: elektric_ai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for elektric_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7b0512b1a16e58017804a41126d1ff4d9252ea63b0964a2f524ec4debe8aca6
MD5 77ae013607c3d1a579c7fc51bdd063a7
BLAKE2b-256 d2a925427396bffa5531bb9f72c93c0ea8c9ee1e733c8d6b50286476a4ca3c1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for elektric_ai-0.1.0-py3-none-any.whl:

Publisher: publish-python.yml on realVasileios/electric

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

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