Skip to main content
Pre-release

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

Semantic Python

Python, but == can understand meaning.

Semantic Python is not a model like Laya or Jev. It is an opt-in Python value layer that turns backend inference into inspectable decisions for normal Python control flow. Only Semantic(...) values can invoke a model.

Install

python -m pip install 'semantic-python[openai]'
export OPENAI_API_KEY="..."

Demo

Use natural-language intent in ordinary loops and async code:

functions · if · try/except · for · while · comprehensions · generators · classes · with · async/await

import asyncio

from semantic_python import (
    OpenAIBackend,
    Semantic,
    UncertainDecisionError,
    configure,
)

STOP = "the user wants to stop"

configure(
    backend=OpenAIBackend(model="gpt-6-luna"),
    true_threshold=0.85,
    false_threshold=0.15,
    uncertainty="raise",
)


def decide(text: str):
    return Semantic(text) == STOP


messages = [
    "Continue with the next ticket.",
    "Save the work and close this session.",
]

for text in messages:
    decision = decide(text)
    print(f"stop={decision.value} p={decision.probability:.2f} model={decision.model}")

    try:
        if decision:
            print("Stop requested")
            break
    except UncertainDecisionError:
        print("Send to human review")


async def decide_async(text: str):
    return await asyncio.to_thread(decide, text)


async_result = asyncio.run(decide_async(text))
opposite = Semantic(text) != STOP

print("async cache hit:", async_result.cached)
print("negated:", opposite.value, opposite.probability)

The comparison returns a bool-coercible Decision, so if and loops work normally while probability, model provenance, caching, and replay remain available. != negates the same judgment instead of issuing a second inference.

More Python patterns

These examples continue with the configured backend and STOP proposition from the main demo.

while

queue = iter(["Keep going", "Not yet", "Finished for today"])
message = Semantic(next(queue))

while message != STOP:
    print("Processing:", message.value)
    message = Semantic(next(queue))

Comprehensions and generators

texts = ["Continue", "Pause here", "That is all for today"]
decisions = {text: decide(text) for text in texts}

stop_requests = [text for text, decision in decisions.items() if decision.value]

probabilities = (decision.probability for decision in decisions.values())
print(stop_requests, list(probabilities))

Classes

from dataclasses import dataclass


@dataclass(frozen=True, slots=True)
class IntentRule:
    proposition: str

    def evaluate(self, text: str):
        return Semantic(text) == self.proposition


stop_rule = IntentRule("the user wants to stop")
decision = stop_rule.evaluate("Please close the session")
print(decision.value, decision.probability)

Context managers and offline tests

from semantic_python import FakeBackend, configuration

state = "I'm done"
fixtures = {(state, STOP): (True, 0.99)}

with configuration(backend=FakeBackend(fixtures), cache=False):
    assert Semantic(state) == STOP

Backends

Application code stays the same when the configured backend changes.

Backend Install Purpose
OpenAIBackend semantic-python[openai] Hosted inference
LayaBackend semantic-python[laya] Local inference
FakeBackend Included Deterministic offline tests

OpenAI receives the wrapped state and proposition. Laya may download model checkpoints on first use. FakeBackend performs no network requests.

Semantics

Expression Result
plain_string == other Ordinary Python equality
Semantic(text) == proposition Inspectable semantic Decision
Semantic(text) != proposition Negated cached judgment
semantic is other Ordinary Python identity
Semantic(...) == Semantic(...) Rejected as ambiguous
hash(Semantic(...)) Rejected; inference is never used for hashing

Probabilities at or above 0.85 resolve true, probabilities at or below 0.15 resolve false, and the default policy raises UncertainDecisionError between those thresholds. Backend failures are raised rather than converted to False.

Examples

The offline examples run without credentials:

python -m pip install -e .
python examples/stop_loop.py
python examples/ticket_routing.py
python examples/escalation.py

Safety

  • Model probability is an estimate, not truth or authorization.
  • Hosted inference can transmit sensitive text and incur cost.
  • Consequential actions should use conservative thresholds and human review.

See semantics, backends, and uncertainty for the complete behavior.

MIT licensed. Experimental and pre-alpha.

Metadata

Release files for semantic-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 semantic-python 0.1.0a1
File Size Uploaded
semantic_python-0.1.0a1.tar.gz 1.5 MB Details

Built distribution (wheel)

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

Total release size: 1.6 MB

Release files / semantic_python-0.1.0a1.tar.gz

Download URL semantic_python-0.1.0a1.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
8868e7077464c5183a121571a611caa5ff55c499a10818579ebc5d1b8317f734
BLAKE2b-256 checksum
How to use checksums
d7680e58313806be237a2657e61067cbd52b0ab4e09d13d90e3faad1d8e81ce2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 8, 2026.

Transparency log

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

Download URL semantic_python-0.1.0a1-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0488e80fcd36d196521e333bcd41d96a843136b593f2336ed495b08f7ba07d38
BLAKE2b-256 checksum
How to use checksums
fcaf5fdd154fc9a664f2aaa5ba0b63dec5242a6af77588a369ccd92013f97e97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0a1 This release

2 release 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