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, andpathlib.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 functionGET /uiserves 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, andpathlib.Path - uses file inputs for
Pathparameters - submits
multipart/form-dataautomatically 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
Pathobjects into the target function
Run the generated FastAPI app with:
uvicorn generated_api:app --reload
Notes
genifacedoes 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2daaa77daebc25982bd55fd69fc33e5d160a0c51455ef744e0b432cbe17341c8
|
|
| MD5 |
c2711234c13307f16df18110080dd702
|
|
| BLAKE2b-256 |
b567f699387ce3b8c97aed6b20cc654b6e3f9004b5c160522161e11594b650fa
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0171653e54a97b9604d07e816fc47119c59f96a8629381befdd7bc0343e22b90
|
|
| MD5 |
3d186ad4d17029966002b56d0ca072f5
|
|
| BLAKE2b-256 |
07cdf13d36b00537200361c5c35dee79df53465907182792749653437098da88
|