Skip to main content

Convert ordinary Python functions into HTTP API endpoints via decorators, with built-in security.

Project description

func_api

Convert ordinary Python functions into HTTP API endpoints with a single decorator.
Zero external dependencies — pure Python standard library.

Installation

pip install func_api

Quick Start

from func_api import FuncAPI

app = FuncAPI(title="My API")

@app.api("/add", methods=["GET", "POST"])
def add(a: int, b: int) -> int:
    return a + b

app.run()  # http://127.0.0.1:8000
curl "http://127.0.0.1:8000/add?a=2&b=3"
# → {"success": true, "data": 5}

Security

Pass security options directly to the @app.api() decorator:

@app.api(
    "/secret",
    methods=["POST"],
    api_key="my-secret-key",       # Require X-API-Key header
    rate_limit=60,                 # Max 60 requests/min per IP
    allowed_origins=["*"],         # CORS allowed origins
)
def secret(msg: str) -> str:
    return f"received: {msg}"
Option Type Description
api_key str Require this value in X-API-Key header
rate_limit int Max calls per minute per client IP
allowed_origins list[str] CORS whitelist (["*"] = any origin)

Features

  • Type-aware parameter parsing — auto-casts from query string / JSON body using type hints
  • GET + POST — query params for GET, JSON body for POST (or both)
  • Built-in /info — auto-generated endpoint listing
  • Zero dependencies — runs on Python 3.9+ with nothing to install

License

MIT

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

func_api-1.0.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

func_api-1.0.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file func_api-1.0.0.tar.gz.

File metadata

  • Download URL: func_api-1.0.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for func_api-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4cf8f8c0fa920a7f4ab3290b4cfd89690c3c8ca7238c9b31b0be13d210e2c33f
MD5 cb5b2d211b2660fc682bbe67a32e6388
BLAKE2b-256 1d992532726e63c75441133289c9c0f4af18f6f811e3c3c1abd82da808d1046b

See more details on using hashes here.

File details

Details for the file func_api-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: func_api-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for func_api-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5596ea17dbf123e868c94cd25c5cb8f5d696ea44d967b4070958d5e82a9c2e10
MD5 c306f273ba6495f63aa18738265d1cd5
BLAKE2b-256 288ae266c9f6d664e7d1332cac8fb0177d24fe6a44cb6a4515226e20524a6611

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