semvec/pypi-packages huggingface dataset:
api-autogen 0.1.0
A simple decorator to convert Python functions into FastAPI endpoints
Requires Python: >=3.7

# 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:
```bash
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:
```python
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 (`add` and `multiply`).
- It registers these functions as API endpoints under the path `/math_funcs/add` and `/math_funcs/multiply`.

### 3. Where the FastAPI App is Defined
- The FastAPI application instance `app` is provided in `api_autogen` and should be used in the main application script.

### 4. Running the API Server
Start the FastAPI application using Uvicorn:
```bash
uvicorn api_autogen:app --reload
```
- The server will start at `http://127.0.0.1:8000`.
- Navigate to `http://127.0.0.1:8000/docs` to 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`.