API AutoGen
Overview
API AutoGen is a Python package that provides a simple way to convert functions into FastAPI endpoints using a decorator.
Installation
To install the package, run:
pip install git+https://github.com/lechplace/api_autogen.git
Example Usage
1. Creating API Endpoints with the @api_func Decorator
Define your functions and use the @api_func decorator to automatically expose them as API endpoints.
Example:
from api_autogen import api_func, app
from pydantic import BaseModel
@api_func("math_funcs")
def add(a: int, b: int) -> int:
return a + b
class MultiplyInput(BaseModel):
a: int
b: int
@api_func("math_funcs")
def multiply(data: MultiplyInput) -> int:
return data.a * data.b
2. Where the Decorator is Used
- The
@api_func("math_funcs")decorator is applied to functions (addandmultiply). - It registers these functions as API endpoints under the path
/math_funcs/addand/math_funcs/multiply.
3. Where the FastAPI App is Defined
- The FastAPI application instance
appis provided inapi_autogenand should be used in the main application script.
4. Running the API Server
Start the FastAPI application using Uvicorn:
uvicorn api_autogen:app --reload
- The server will start at
http://127.0.0.1:8000. - Navigate to
http://127.0.0.1:8000/docsto explore the auto-generated API documentation.
Project Structure
api_autogen/
│── __init__.py # Exposes api_func and app
│── decorator.py # Implements the decorator logic
setup.py # Package setup file
README.md # Documentation
Summary
- Use
@api_func(package_name)to convert functions into API endpoints. - The FastAPI app is provided in
api_autogen. - Run the server with
uvicorn api_autogen:app --reload. - API documentation is available at
/docs.
Metadata
Release files for api-autogen 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| api_autogen-0.1.0.tar.gz | 2.8 kB | Details |
Release files / api_autogen-0.1.0.tar.gz
| Download URL | api_autogen-0.1.0.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
032dbc544a23b7922c391ab54ca5100d3acd51cca5958c8c7f196a444696876c
|
|
BLAKE2b-256 checksum How to use checksums |
e7e3046da0bfb2cbd48cee4e6b5902d31004ec55530bd7c9b59076cb6701f56b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|