Skip to main content

Contract-first adapters for turning Python functions into portable interfaces.

Project description

geniface

geniface turns plain Python functions into small, portable interfaces:

  • a command-line runner
  • a built-in HTTP server with a browser UI
  • generated adapter code such as FastAPI

It stays close to the function signature and uses standard library tooling where possible.

Installation

geniface is intended to be installed from PyPI:

pip install geniface

Requirements:

  • Python 3.10+

Optional packages:

  • For development and tests:
pip install "geniface[dev]"
  • For generated FastAPI adapters, install FastAPI and a server:
pip install fastapi python-multipart uvicorn

Quick Example

Create a module with a function:

# demo.py
from pathlib import Path


def greet(name: str, excited: bool = False) -> str:
    return f"hello {name}!" if excited else f"hello {name}"


def read_file(path: Path) -> str:
    return path.read_text(encoding="utf-8")

Run

Run a function directly from the command line:

python -m geniface.run demo:greet Ada --excited true

Output:

hello Ada!

Rules:

  • required parameters are positional
  • parameters with defaults are passed as flags
  • supported primitive CLI types are str, int, float, bool, and pathlib.Path

Examples:

python -m geniface.run demo:greet Ada
python -m geniface.run demo:read_file ./notes.txt

Serve

Start the built-in HTTP server:

python -m geniface.serve --host 127.0.0.1 --port 8000 demo:greet

When the server is ready it prints the bound address:

Serving on http://127.0.0.1:8000

Available endpoints:

  • POST /<function_name> executes the function
  • GET /ui serves a browser form generated from the function signature

For the greet example, send JSON to:

curl -X POST http://127.0.0.1:8000/greet \
  -H "Content-Type: application/json" \
  -d '{"name":"Ada","excited":true}'

The response shape is always:

{"result": "hello Ada!"}

Browser UI

Open:

http://127.0.0.1:8000/ui

The UI:

  • builds a form from the function signature
  • supports str, int, float, bool, and pathlib.Path
  • uses file inputs for Path parameters
  • submits multipart/form-data automatically when file inputs are present

Generate

Generate adapter code from a function:

python -m geniface.generate demo:greet --target fastapi --output generated_api.py

Currently supported targets:

  • fastapi

This writes a Python file that imports the target function and exposes a FastAPI app with a single POST endpoint at /<function_name>.

For functions without file inputs, the generated adapter accepts JSON.

For functions with pathlib.Path parameters, the generated adapter:

  • exposes file uploads with UploadFile = File(...)
  • uses Form(...) for non-file parameters
  • writes uploaded files to temporary files
  • passes Path objects into the target function

Run the generated FastAPI app with:

uvicorn generated_api:app --reload

Notes

  • geniface does not validate beyond the underlying Python call and parser behavior.
  • Uploaded files are written to temporary files and are not deleted automatically.
  • The package is licensed under the MIT License. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geniface-0.1.0.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

geniface-0.1.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file geniface-0.1.0.tar.gz.

File metadata

  • Download URL: geniface-0.1.0.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for geniface-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2daaa77daebc25982bd55fd69fc33e5d160a0c51455ef744e0b432cbe17341c8
MD5 c2711234c13307f16df18110080dd702
BLAKE2b-256 b567f699387ce3b8c97aed6b20cc654b6e3f9004b5c160522161e11594b650fa

See more details on using hashes here.

File details

Details for the file geniface-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: geniface-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for geniface-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0171653e54a97b9604d07e816fc47119c59f96a8629381befdd7bc0343e22b90
MD5 3d186ad4d17029966002b56d0ca072f5
BLAKE2b-256 07cdf13d36b00537200361c5c35dee79df53465907182792749653437098da88

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page