Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

partial-python

Execute append-only Python while source is still arriving. Python 3.11+, no runtime dependencies. Experimental API.

uv add 'partial-python==0.1.0a1'

Input and completion

Use an Executor for each logical response. Feed source as it arrives, then explicitly finish or abort according to the provider's completion status.

from partial_python import Executor

executor = Executor({"foo": foo, "bar": bar, "baz": baz})
await executor.feed("await foo(1)\n")  # Executes now.
await executor.feed("await bar(2)")  # Waits: an operator or attribute access may follow.
await executor.feed("\nawait baz(3)")  # Executes bar, buffers baz.
await executor.finish()  # Successful EOF permits baz.

Units execute in source order, at most once each. New input never reruns earlier units. A loop still performs its ordinary iterations, but its whole body must be sealed before execution starts.

feed() accepts new text deltas, not accumulated snapshots. feed() and finish() return completed Execution events. The executor retains events, failed_unit, sealed but unstarted queued units, and an immutable parser_state snapshot containing the unsealed pending tail. Read results from executor.namespace.

finish() declares successful source completion. On disconnects, token limits, cancellation, or failed responses, use abort() for an idle executor; cancel and await an active operation first. Failure is terminal: earlier effects remain, later units do not start, and nothing is retried. Lifecycle and integration.

Async text iterators

When your adapter already supplies a validated async text iterator, incremental_exec() is a convenience wrapper. validated_deltas must yield raw source and end normally only after successful generation. Its adapter must raise on truncation, failure, or a missing completion signal.

from partial_python import incremental_exec

namespace = await incremental_exec(validated_deltas, {"foo": foo, "bar": bar})

Execution starts while source is arriving; the await completes after execution and returns the namespace used. To consume events as each unit completes, use Executor.stream() and retain the executor for diagnostics. Close a partially consumed event iterator with aclosing in its owning task/context. Streaming adapter.

Stable boundaries

Input Execution boundary
Top-level simple statement A real logical newline or successful EOF.
foo() at temporary EOF Wait; it can still become foo() + bar().
for, if, try, def, and other compounds Hold the entire statement until an unambiguous top-level successor or successful EOF.
else, elif, except, finally, or an ambiguous prefix such as e Keep clauses attached; wait for ambiguous prefixes to resolve.
Blank lines and comments Preserve them; they do not close a suite.
Decorators, brackets, line joins, and strings Keep their complete logical statement together.

Parser.feed() / finish() expose the same boundaries as immutable CodeUnit source slices without executing them. pending retains the uncommitted suffix. Every unit preserves original characters and source positions; no repaired text is executed. Precise semantic contract.

Display completion

from partial_python import Allow, complete

assert complete("ready = 1\nvalue = ['hel").source == "ready = 1\n"
preview = complete("value = ['hel", Allow.STRING | Allow.BRACKET)
assert preview.source == "value = ['hel']"
assert preview.provisional

The default returns only the stable prefix. Allow flags opt into provisional display; prefix, suffix, and withheld distinguish original text from synthetic text. A preview never authorizes execution, even when its suffix is empty. Preview options and limits.

Execution scope

Units share one namespace and support native top-level await. Execution requires an asyncio event loop; use the asyncio backend with AnyIO. Parser and complete are synchronous.

This uses sequential compilation units, with explicit differences from whole-module execution. Future imports remain in the prologue, only the initial string sets the module docstring, and module-scope global declarations are rejected. On Python 3.14+, module annotations require an explicit from __future__ import annotations.

In-process execution provides no sandbox or rollback. Hosts own permissions, background tasks, source limits, and hard deadlines. The integration examples demonstrate transport completion, concurrent reception, and traceback source lifetime.

Development

uv sync
uv run pytest
uv run basedpyright
uv run ruff check .
uv run ruff format --check .
uv run examples/streaming_tools.py
uv build

API and transport · Design · Validation · Related implementations

Metadata

Release files for partial-python 0.1.0a1

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

Source distribution (sdist)

Source distribution for partial-python 0.1.0a1
File Size Uploaded Provenance Actions
partial_python-0.1.0a1.tar.gz 105.2 kB Without provenance Details for partial_python-0.1.0a1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for partial-python 0.1.0a1
File Interpreter ABI Platform Actions
partial_python-0.1.0a1-py3-none-any.whl Python 3 none any Details for partial_python-0.1.0a1-py3-none-any.whl

Total release size: 122.5 kB

Release files / partial_python-0.1.0a1.tar.gz

Download URL partial_python-0.1.0a1.tar.gz
Size 105.2 kB
Tags Source
SHA-256 checksum
How to use checksums
56b6cc54ccbb72506cb9218883ac7b21823cdd138bf51025f2305ece929a5150
BLAKE2b-256 checksum
How to use checksums
9c82e82a765d1e503e3440533125cae245452390ecaaec26eda6ad22e14ee6a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / partial_python-0.1.0a1-py3-none-any.whl

Download URL partial_python-0.1.0a1-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e69b107f2bd51a95854b885445a96fae27f04e33f63ececdb4bb5bba50824f04
BLAKE2b-256 checksum
How to use checksums
8e616589ec3d1153cdec217526d9296c846ee960ee095f2f057d537fbb0939ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for partial-python 0.1.0a1

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