Skip to content

offerrall/FuncToWeb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

229 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Func To Web 1.5.0

PyPI version Python License

Type hints → Web UI. Turn Python functions into web apps — standalone or mounted inside yours.

func-to-web Demo

One typed Python function → form + iframe + HTTP endpoint, simultaneously. It's a library, not a framework: it composes with what you already have.

  • Standalonerun(func). Internal tools, admin panels, scripts. The auto-generated UI is the app.
  • Mountedcreate_app(funcs) returns a plain FastAPI app. Mount it under any prefix of your existing app; every URL adapts automatically.
  • Embedded — drop forms into existing sites via <iframe> with URL prefill. "Export to PDF" buttons, CSV importers, modal editors.
  • Backend for your own SPA — drop your built bundle in front_dir= and static files in assets_dir= — served alongside your functions by the same process.

Validation, file uploads, SSE streaming, downloads, custom widgets and outputs via return types and Annotated metadata — all built-in. Auto-generated API docs at /doc for scripts and AI agents: write a function, get a UI and an API for free.

Quick start

pip install func-to-web
from func_to_web import run

def divide(a: float, b: float):
    return a / b

run(divide)

divide demo

Open http://127.0.0.1:8000. Done.

Or mount it inside your FastAPI app

from fastapi import FastAPI
from func_to_web import create_app

def add(a: int, b: int):
    return a + b

host = FastAPI()
host.mount("/tools", create_app(add))
uvicorn app:host

Open http://127.0.0.1:8000/tools. Forms, validation, downloads, navigation — everything works under the prefix, zero configuration.

Full docs with examples and screenshots: offerrall.github.io/FuncToWeb

Inputs

Type Widget Docs
int, float Number / slider
str, Email Text / textarea / password
bool Toggle
date, time Pickers
Color Hex picker
File, ImageFile, VideoFile, ... Upload
Literal, Enum, Dropdown(func) Select
list[T] Dynamic list
T | None Toggle + input
Params Reusable groups
Annotated[T, ...] Type Composition, Constraints, labels, sliders

Outputs

Return type Rendered as Docs
str, int, float, None Text + copy button
PIL Image, Matplotlib Figure Inline image
FileResponse Download button
DataFrame, list[dict], ... Table
ActionTable Clickable rows → next function
tuple / list Multiple outputs
print() Streamed live

Features

  • create_app() — get a mountable FastAPI app, serve by import string (workers, reload) — docs
  • Multiple functions with index page or groups — docs
  • URL prefill — open forms with values from query params — docs
  • Embed mode — drop any form into your site via ?__embed=1docs
  • Auto-generated API docs at /doc for scripts and AI agents — docs
  • Dark modedocs
  • Server config — host, port, reverse proxy — docs

Examples

File transfer

from func_to_web import run, File
import shutil, os

downloads = os.path.expanduser("~/Downloads")

def upload_files(files: list[File]):
    for f in files:
        shutil.move(f, downloads)
    return "Done."

run(upload_files)

QR code generator

import qrcode
from func_to_web import run

def make_qr(text: str):
    return qrcode.make(text).get_image()

run(make_qr)

Admin panel

import subprocess
from typing import Literal
from func_to_web import run

def restart_service(service: Literal['nginx', 'gunicorn', 'celery']):
    subprocess.run(["sudo", "supervisorctl", "restart", service], check=True)
    return f"{service} restarted."

# Deploy sensitive tools behind a reverse proxy with auth (e.g. Nginx
# basic auth) — see docs/config.md.
run(restart_service)

More in examples/ — including a full CRUD app in 70 lines using Params + ActionTable.

Install

pip install func-to-web                                     # stable
pip install git+https://github.com/offerrall/FuncToWeb.git  # latest

Requirements: Python 3.10+. Core deps installed automatically; Pillow, Matplotlib, Pandas, NumPy and Polars are optional.

Built on pytypeinput and pytypeinputweb, usable standalone for CLIs, Qt apps, etc.

Feedback, issues and contributions welcome — they keep the project moving.

MIT License · Made by Beltrán Offerrall

About

Type hints → Web UI. Turn Python functions into web apps — standalone or mounted inside yours.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors