Skip to main content

pylekto

Async Python client for the Lekto DMS REST API.

pylekto reaches every operation of the API an API token may use: auth (who calls), health, version (and whether a newer Lekto is out), documents (with uploads, downloads, facts, page edits, changes of many documents), search, relations, the master data (contacts, document_types, tags, fields), spaces, users, identifiers, the open_identifiers, the inbox, the expected documents, lenses, rules (with templates), mailboxes, mail_rules, webhooks, push, the pipeline, jobs, automation, the classifier and the events as they happen. pylekto.webhooks receives what Lekto sends to a webhook.

import asyncio

from pylekto import LektoClient


async def main() -> None:
    async with LektoClient("https://lekto.example.com", "lekto_…") as lekto:
        me = await lekto.auth.me()
        print(me.user.username, me.token_scope)

        async for document in lekto.documents.list(lane=["red"]):
            print(document.title)

        inbox = await lekto.documents.count(in_inbox=True)
        print(inbox.total)

        result = await lekto.search.page("electricity bill", limit=5)
        print([hit.document.title for hit in result.items])

        async for event in lekto.events.listen():  # until the stream ends or raises a LektoError
            print(event.type, event.document_id)


asyncio.run(main())
  • Token only. A personal API token from Lekto; its rights (chosen one by one, or a preset: read, read_write, upload) decide what the client may do, and lekto.auth.me() names them.
  • Your own httpx2 client if you like (LektoClient(url, token, client=...)): pylekto sends its requests with it and leaves it open.
  • Errors raise. Each subclass of LektoError says what went wrong; a refusal carries Lekto's problem details with a reason code. pylekto repeats nothing: whether to try again is up to you.
  • New values read. A choice in the models is Literal[...] | Unknown: a value that a newer Lekto sends and this pylekto does not know arrives as pylekto.Unknown (a str) instead of failing; case Unknown(): matches it.
  • One version of the API. pylekto speaks the API pylekto.API_VERSION of Lekto pylekto.LEKTO_VERSION; its models are generated from that release's OpenAPI description. From 0.2.0 on, pylekto's version names that API: pylekto X.Y.Z speaks the API X.Y, so pylekto==0.3.* stays with the API 0.3. Withdrawn: 0.3.0 (API 0.2) and 0.4.0 (API 0.3, again as 0.3.1). Connecting to a Lekto whose API may differ warns (LektoVersionWarning): during the beta (0.x) every other MINOR, from 1.0 on another MAJOR or a smaller MINOR. pylekto.api_fit(lekto.api_version) returns the same rule as "fits", "newer" (update pylekto), "older" (update Lekto) or "unknown" (no or an unreadable version).

Receiving webhooks

Lekto signs what it sends to a webhook (Standard Webhooks). In whatever web framework receives it:

from pylekto import webhooks
from pylekto.models import TaskAnswer


async def receive(headers: dict[str, str], body: bytes) -> None:
    webhooks.verify(headers, body, "whsec_…")  # raises WebhookVerificationError
    asked = webhooks.read_rule_ask(body)  # or read_event, read_rule_send, read_propose …
    task = webhooks.task(headers)
    if task is not None:
        await webhooks.answer(task, TaskAnswer(status="ok", answer={"paid": True}))

Requirements

Python 3.14 or newer.

Development

Open the repository in its devcontainer (.devcontainer/); it runs script/setup, which installs the dependencies and the Git hooks. Outside the devcontainer, script/setup creates a local .venv first.

uv sync
uv run prek run --all-files   # every check: Ruff, mypy, pytest with coverage, typos, yamllint

License

MIT, see LICENSE.

Metadata

Release files for pylekto 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylekto 0.3.1
File Size Uploaded Provenance Actions
pylekto-0.3.1.tar.gz 102.6 kB With provenance Details for pylekto-0.3.1.tar.gz

Built distribution (wheel)

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

Total release size: 216.0 kB

Release files / pylekto-0.3.1.tar.gz

Download URL pylekto-0.3.1.tar.gz
Size 102.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6bb37fe80ee038c47dd412b4cf82953cbdbb993adb7e68a105a27e855c4b88ba
BLAKE2b-256 checksum
How to use checksums
a64125a015a6dbbb9b74982d14927ea39c2f311673bf80def892fabf4b009b49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / pylekto-0.3.1-py3-none-any.whl

Download URL pylekto-0.3.1-py3-none-any.whl
Size 113.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c7789f61a106e02dcfa939e2933f6cd33ebdf91613ae441cb066f66f9ec29591
BLAKE2b-256 checksum
How to use checksums
ef9d62778c9776aea86564cd1ebf00fba2217286116b622c2a588159f1c4b457
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for pylekto 0.3.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pylekto-0.3.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

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