Skip to main content

expose_interface

Export ordinary Python functions and bound methods as command line programs. The package uses the standard library and supports Python 3.11 and later.

Install

python -m pip install expose-interface

Releases

Publish a GitHub release with a tag matching the package version, such as v0.1.0. .github/workflows/release.yaml tests and verifies the distributions before publishing to PyPI through the pypi environment using Trusted Publishing. The workflow can also be run manually against an existing release tag.

Define an interface

from expose_interface import Interface, argument, flag, option

app = Interface("hello", description="Greeting programs.")

@app.program
@argument("name")
@option("--count", "-n", help="Number of greetings.")
@flag("--color", "-G", help="Enable color.")
def greet(name: str, *, count: int = 1, color: bool = False):
    """Greet someone a chosen number of times."""
    for _ in range(count):
        print(f"Hello, {name}!")

main = app.main

Decorators register metadata and return the original function. Ordinary calls such as greet("World", count=2) continue to work. Required positional parameters are inferred as arguments, defaults and keyword-only parameters as options, and Boolean options as flags. Decorators supply aliases and help or override that classification. They can appear above or below @app.program.

The program name defaults to the function name with underscores changed to hyphens. Use @app.program(name=None) for a program invoked at the bare interface name. A default with positional arguments must have its own interface to keep those inputs distinct from subcommand names.

Run from a module or install a shell command

For a source module named hello.py in the current directory:

python -m expose_interface hello:app greet World -n 2
python -m expose_interface hello:app --help
python -m expose_interface hello:app greet --help

The launcher imports only the explicitly requested module. For installed, importable modules, the expose-interface hello:app ... console command also works. For current-directory source files, python -m places that directory on Python's import path.

Export the application's own executable through its pyproject.toml:

[project.scripts]
hello = "hello:main"
hi = "hello:main"

After installing that application, its environment's bin directory (Scripts on Windows) contains both commands. Both invoke the same interface. The library does not write executables elsewhere on the system. Development consumers can also install this source checkout.

Arguments, options and flags

These positional declarations are equivalent:

@app.program(arguments=["first", "second"])
def combine(first: str, second: str): ...

# Alternatively: @arguments("first", "second") below or above @app.program.
# One parameter: @app.program(argument="first") or @argument("first").

Scalar inputs support str, int, float, Path, Enum values and Literal choices. Nullable options use T | None. Collections use list[T] or tuple[T, ...]: positional collections consume multiple tokens, and option collections accept repeated switches. An explicit type= supplies a custom converter. Variadic Python signatures and arbitrary unions/models fail clearly.

@app.program
@option("--plugin", dest="plugins", multiple=True)
def inspect_plugins(plugins: tuple[str, ...] = ()):
    print(plugins)

Flags support --flag and --no-flag. A callback configures another concern after parsing and before the program:

def configure_color():
    print("Color selected")

@app.program
@flag("--color", "-G", mtd=configure_color)
def display(color: bool = False): ...

Callbacks accept no required arguments and run only when the positive flag is explicitly selected. Bound methods can use mtd=True to resolve the flag's destination on their instance, or mtd="method_name" to choose a method.

Nested commands and invocation context

from expose_interface import Context

def setup(context: Context, verbose: bool = False):
    context.obj = {"verbose": verbose}

root = Interface("tools", setup=setup)
files = Interface("files", description="File programs.")
root.add_interface(files)

@files.program
def show(context: Context, path: str):
    print(context.obj, path)

root.invoke(["--verbose", "files", "show", "notes.md"])

Context is injected and is never a CLI argument. Each invocation has fresh state. Parent options precede the child name; child options follow their command name. Help and invalid input never execute setup, flag callbacks or programs. Sync and async setup/callbacks/programs are supported. Use await app.invoke_async inside an existing event loop; app.invoke runs from synchronous Python.

invoke returns the callable's result without printing it. main is the shell boundary: success exits 0, UsageError exits 2 and expected CommandError exits 1. Unexpected exceptions keep their traceback. Functions print/serialize their own output; integer return values are not shell exit codes.

Help and configuration

-h and --help show full cleaned program docstrings. Interface help shows its description and alphabetical program summaries. Set order=0 to put a program first within its section, and section="Files" to group it. Child mounts accept the same order and section fields. Sections sort alphabetically; ungrouped programs come first. Default-program docstrings appear in interface help too.

[tool.expose-interface]
name = "hello"
description = "Greeting programs."

Load a specific file with Interface.from_toml("pyproject.toml"). Configuration never searches directories or imports commands. app.format_help() renders help without executing user code.

For module-level decorators, @program(interface=".") registers on the defining module's default interface; get_interface().main exports it. Declare a named module interface with interface("tools"); duplicate declarations in that module raise DefinitionError. The program, expose, command and cli decorators are aliases. API details describe validation and defaults.

Development

uv sync --locked
uv run python -m unittest discover -s tests -v
uv build

The development interpreter is Python 3.14. CI tests the supported Python floor and current interpreter on Linux, plus Windows and macOS. Distribution checks build a wheel/source archive and exercise an installed wheel outside the checkout.

Releases and package publication are separate from source development.

The design and task queue tracks the initial contract and Hidden Moves adoption.

The Hidden Moves adapter and conformance suite verify nested commands, provider loading, JSON contracts and async results against the real consumer API without adding consumer dependencies to this library.

Metadata

Release files for expose-interface 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 expose-interface 0.1.0
File Size Uploaded Provenance Actions
expose_interface-0.1.0.tar.gz 13.4 kB With provenance Details for expose_interface-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for expose-interface 0.1.0
File Interpreter ABI Platform Actions
expose_interface-0.1.0-py3-none-any.whl Python 3 none any Details for expose_interface-0.1.0-py3-none-any.whl

Total release size: 30.3 kB

Release files / expose_interface-0.1.0.tar.gz

Download URL expose_interface-0.1.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
76c74d5e0fbae7a1c715ec7aaf89403644a67c0bd8a861eb0fe2d38059ef5dda
BLAKE2b-256 checksum
How to use checksums
5c59eea6d779e745ec08aa66fe500b8a538653f42d01036aa1092dfebb01ab9f
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 15, 2026.

Transparency log

Release files / expose_interface-0.1.0-py3-none-any.whl

Download URL expose_interface-0.1.0-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ec6736b98e777ea63dcfe4fd99e87e2fade3e27fc659acace919bed8860d689
BLAKE2b-256 checksum
How to use checksums
12e9935d1d85232a02cad3e7c37ec1597e3771fad25a1cd1bb49cc58f4522414
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 15, 2026.

Transparency log

Security for expose-interface 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

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

Select from 2 files

Attestation for expose_interface-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 Oct 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

2 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