Skip to main content

Efct

简体中文

Efct is a static effect and pure-function verifier for a closed, auditable subset of Python. It checks what a function can observe, change, raise, or fail to return from, and rejects code it cannot prove safe.

Efct is currently alpha software. It supports CPython 3.13 and 3.14.

Installation

Install Efct from PyPI:

python -m pip install efct

With uv:

uv add efct

Confirm the installation:

efct --version

Quick start

Decorate a function with @efct.pure:

import efct


@efct.pure
def add(left: int, right: int) -> int:
    return left + right


assert add(2, 3) == 5

When the module is imported, Efct validates its source, types, calls, and effects. A successful decoration returns a verified PureFunction. Validation failure raises EfctStartupError and stops the module from importing.

You can also check files without importing them:

efct check app.py
efct check src/

Efct rejects unknown syntax, unknown calls, mutable values crossing function boundaries, and behavior outside a declared effect bound. It never treats unverified code as pure.

Pure functions and partial behavior

Efct separates external effects from partial behavior:

  • External effects interact with or depend on the outside world, such as files, networks, clocks, randomness, environment variables, processes, and global state.
  • Partial behavior means a computation may not return normally, such as raising an exception or diverging.

The three forms of pure have deliberately different meanings:

Declaration External effects Partial behavior
@efct.pure Forbidden Inferred and propagated
@efct.pure() Forbidden Explicitly empty
@efct.pure(...) Forbidden Explicit allowlist

Use the bare decorator while implementing a function:

@efct.pure
def parse(value: str) -> int:
    if value == "":
        raise ValueError("empty")
    return 1

Efct infers Raise(ValueError) and propagates it to callers.

Use an explicit allowlist at a stable API boundary:

@efct.pure(efct.partial.Raise(ValueError))
def parse(value: str) -> int:
    if value == "":
        raise ValueError("empty")
    return 1

Use empty parentheses when the function must have no modeled partial behavior and must be proven to terminate:

@efct.pure()
def increment(value: int) -> int:
    return value + 1

Efct models these partial behaviors:

  • efct.partial.Raise(ExceptionType)
  • efct.partial.RaiseGroup(ExceptionType)
  • efct.partial.Diverge()

An explicit declaration is an upper bound. A function may produce fewer behaviors than declared, but it cannot produce an undeclared one.

Declaring effects

Use @efct.effects(...) when a function intentionally interacts with the outside world:

import efct


@efct.effects(
    efct.effect.Console(),
    efct.partial.Raise(OSError),
    efct.partial.Raise(ValueError),
)
def show(value: int) -> None:
    print(value)

print has a console effect and may fail with the modeled OSError or ValueError paths. All three behaviors are therefore part of the public bound.

Available external effect declarations are:

  • efct.effect.Console()
  • efct.effect.File.Read() and efct.effect.File.Write()
  • efct.effect.Network()
  • efct.effect.Clock()
  • efct.effect.Random()
  • efct.effect.Environment()
  • efct.effect.Process()
  • efct.effect.State.Read() and efct.effect.State.Write()
  • efct.effect.Unsafe()

Stable string declarations remain available:

@efct.effects("console", "raise:builtins.OSError", "raise:builtins.ValueError")
def show(value: int) -> None:
    print(value)

Do not mix typed declarations and string declarations in the same decorator.

Handling exceptions

Handled exceptions are removed from the outward partial bound:

@efct.pure()
def item_or_zero(values: tuple[int, ...], index: int) -> int:
    try:
        return values[index]
    except IndexError:
        return 0

Efct tracks exception inheritance, ordered handlers, except ... as error, exact re-raising, try ... else, finally, contextlib.suppress, exception groups, and supported except* flows. Unmatched exceptions continue to propagate.

For expected application failures, prefer Result data:

@efct.pure
def parse(value: str) -> efct.Result[int, str]:
    if value == "":
        return efct.Err("empty")
    return efct.Ok(1)

Result supports exhaustive match over Ok and Err.

Pure records

The same decorator can verify a deeply immutable record:

from dataclasses import dataclass

import efct


@efct.pure
@dataclass(frozen=True, slots=True)
class Point:
    x: int
    y: int

Values crossing a verified function boundary must belong to Efct's supported immutable value model.

Higher-order functions

PureCallable accepts a verified function with an explicitly empty effect and partial bound:

@efct.pure()
def apply(
    function: efct.PureCallable[[int], int],
    value: int,
) -> int:
    return function(value)

Effect-polymorphic functions preserve the concrete effects of a callback:

@efct.effects
def apply_effect[E: efct.EffectSet](
    function: efct.EffectCallable[[int], int, E],
    value: int,
) -> int:
    return function(value)

The effect variable E is instantiated from the callback certificate at each call site.

Module initialization

Function decorators do not automatically certify arbitrary top-level module code. Declare a module initialization contract with the reserved _efct name:

import efct

_efct = efct.pure

For effectful initialization, declare an explicit upper bound:

_efct = efct.effects(
    efct.effect.Console(),
    efct.partial.Raise(OSError),
    efct.partial.Raise(ValueError),
)

Without _efct, the module may still run, but Efct makes no claim about its initialization effects.

Command line

efct check app.py
efct check src/
efct check src/ --format=json
efct check src/ --verified-only
efct check src/ --deny-unsafe
efct trust fingerprint pytest
efct run app.py
efct --version

efct check analyzes code without executing it. A zero exit status means the source snapshot described by the report passed verification.

efct run verifies the entry point and its local dependency closure before executing a verified source snapshot. Change the source, dependencies, or Python runtime and it must be checked again.

External libraries

Third-party symbols are never considered pure automatically. Declare an unaudited boundary explicitly when migration is still in progress:

schema = 1

[[symbol]]
trust = "unsafe"
path = "legacy.math.clamp"
signature = "(int, int, int) -> int"
effects = []
partials = []
reason = "the implementation has not been audited"

An unsafe call contributes the unsafe effect. Use --deny-unsafe in CI to reject it.

An audited boundary binds the public contract to exact installed distributions and to the callable's real implementation:

schema = 1

[python]
implementation = "cpython"
version = "3.14.7"
cache_tag = "cpython-314"

[[distribution]]
name = "ourlib"
version = "1.4.2"
installation_sha256 = "..."
dependencies = []

[[symbol]]
trust = "audited"
path = "ourlib.math.clamp"
owner = "ourlib"
implementation = { kind = "python", path = "ourlib.math.clamp" }
signature = "(int, int, int) -> int"
effects = []
partials = []

Generate the installation fields instead of calculating the digest manually:

efct trust fingerprint ourlib
efct trust fingerprint ourlib --format=json

List every audited direct dependency in dependencies and add a corresponding [[distribution]] block. Native extension functions use kind = "native". Efct rejects stale digests, missing installation records, editable installations, undeclared dependency references, mismatched module ownership, replaced runtime callables, and Python code objects that do not match the hashed installation source. It never falls back from audited to unsafe.

path is the public export used by application code. implementation.path identifies the function that actually implements it, so audited re-exports can point into a declared dependency. effects contains only external effects; partials contains raise:..., raise-group:..., or diverge.

Runtime enforcement

Verified wrappers enforce the certificate when called:

  • EfctContractError reports an argument contract violation.
  • EfctIntegrityError reports changed code, bindings, dependencies, or an invalid return value.
  • EfctStartupError reports source or verification failure during decoration.

Argument and return types are exact. Rebinding a verified dependency invalidates the certificate instead of silently widening it. Audited distribution contents are checked when the certificate is issued; subsequent calls revalidate the loaded object identities and Python code object identity.

Supported Python boundary

Efct intentionally supports a strict subset of Python. Common supported features include immutable primitive values, tuples, frozenset, FrozenMap, optional values, Result, local control flow, finite iteration, analyzed while loops, restricted local lists, static imports, verified cross-module calls, and registered standard-library operations.

Dynamic imports, reflection, monkey patching, ordinary mutable objects crossing boundaries, unknown third-party calls, and unsupported context managers are rejected. Efct is a verifier, not a Python sandbox.

License

Efct is available under the MIT License.

Metadata

Release files for efct 0.1.0

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

Source distribution (sdist)

Source distribution for efct 0.1.0
File Size Uploaded Provenance Actions
efct-0.1.0.tar.gz 154.5 kB With provenance Details for efct-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for efct 0.1.0
File Actions
efct-0.1.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for efct-0.1.0-cp314-cp314-win_amd64.whl
efct-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details for efct-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
efct-0.1.0-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for efct-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
efct-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 macOS 10.12+ x86-64 Details for efct-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl
efct-0.1.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for efct-0.1.0-cp313-cp313-win_amd64.whl
efct-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for efct-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
efct-0.1.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for efct-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
efct-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.12+ x86-64 Details for efct-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl

Total release size: 14.3 MB

Release files / efct-0.1.0.tar.gz

Download URL efct-0.1.0.tar.gz
Size 154.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7b5ff31e10f3e36173fcc367219b264fc9c3ab4f8286abf914b3e65f157d8421
BLAKE2b-256 checksum
How to use checksums
ee29c394f1b893ebc1a057360539ef9b5d0577b6dc4f3feedcee0d18920f7826
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 Aug 15, 2026.

Transparency log

Release files / efct-0.1.0-cp314-cp314-win_amd64.whl

Download URL efct-0.1.0-cp314-cp314-win_amd64.whl
Size 1.7 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
5d99986b23a799dd10a8cecac08257147ab81f7f30bcd3904fd8c95c1d9012e0
BLAKE2b-256 checksum
How to use checksums
44fcb4723642a034f8f77b7b890116de2af2dc12357d01f0a0d006172a4c252b
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 Aug 15, 2026.

Transparency log

Release files / efct-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL efct-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.9 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b051185ca20dab48aa6430de00f872c444765d2b82ef823cf234fdbde07c1918
BLAKE2b-256 checksum
How to use checksums
8c4ca914def2599e97501683522f8ab05f3362c90f2ca6a8da0751bf03e2e287
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 Aug 15, 2026.

Transparency log

Release files / efct-0.1.0-cp314-cp314-macosx_11_0_arm64.whl

Download URL efct-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
Size 1.7 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3afea2f08ea3fda875a9bd73382eb924f35bc6a86a23ac7892e208a82bcdd809
BLAKE2b-256 checksum
How to use checksums
3a412f4ce48a4c3d5f337377180352a15be427f75a4ee35802b1bfcbbd50a506
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 Aug 15, 2026.

Transparency log

Release files / efct-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl

Download URL efct-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl
Size 1.8 MB
Tags CPython 3.14 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
672a1f52e966c0ffa5ff4f7a72e2ec47f42cd56dace4907afa1e842f0b9af87f
BLAKE2b-256 checksum
How to use checksums
de39d2e192e30e04e91556e4424c8be29bf0c738f0e36dda7994befb1488c377
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 Aug 15, 2026.

Transparency log

Release files / efct-0.1.0-cp313-cp313-win_amd64.whl

Download URL efct-0.1.0-cp313-cp313-win_amd64.whl
Size 1.7 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
2c3ffcfd5a3eefe25940eb860d0f6e2127d119012f43d5d9961510043b84f44f
BLAKE2b-256 checksum
How to use checksums
5c005325207564902d6959c0e0804937d7d3daeb4a60b3c664e05318bc92daee
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 Aug 15, 2026.

Transparency log

Release files / efct-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL efct-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
97c73ffbe2aff0cfbde35be3e3f9af7a306f5207e2637a6f7ac594d88bef2c02
BLAKE2b-256 checksum
How to use checksums
b1343797e0a47188f0edf0531da83215d548f7fe0bf497b93ee9e91c25ce622d
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 Aug 15, 2026.

Transparency log

Release files / efct-0.1.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL efct-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Size 1.7 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
52fa79f151d096a43fe9452576ee8b89a5a7e9719d7c1d2ccee7732394d820b7
BLAKE2b-256 checksum
How to use checksums
2d3a4d0376c754c9227456e9d17585c7279512f7c771e455c32bd6030b9e7c88
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 Aug 15, 2026.

Transparency log

Release files / efct-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl

Download URL efct-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl
Size 1.8 MB
Tags CPython 3.13 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
127170327772ee0c7daa37002d2bd897035de71cd0a5a8ed3e56ae333216955b
BLAKE2b-256 checksum
How to use checksums
15572a5a7a187eceae5edf0512ae55867618801efd62e2859d141e5d96bb3d29
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 Aug 15, 2026.

Transparency log

Security for efct 0.1.0

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

All 9 files in this release have been uploaded with provenance metadata.

Select from 9 files

Attestation for efct-0.1.0.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 Aug 15, 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

9 release files Full provenance

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