Metadata-Version: 2.1
Name: fastapi-decorators
Version: 0.0.3
Summary: Decorate FastAPI endpoints with custom decorators.
Home-page: https://github.com/Minibrams/fastapi-decorators
Author: Anders Brams
Author-email: anders@brams.dk
Keywords: fastapi,decorators,middleware,dependency,dependencies
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastapi

# FastAPI decorators

Small Python utility for wrapping your FastAPI endpoints in custom decorators.

## Installation
```bash
pip install fastapi-decorators
```

## Usage
Create a simple decorator that rejects unauthorized requests:

```python

oauth2_scheme = OAuth2PasswordBearer(
    tokenUrl="/api/v1/auth/login", 
    auto_error=False,
)

def authorize(*required_scopes: str):
    def decorator(func):
        def dependency(
            token: Optional[str] = Depends(oauth2_password_scheme),
            db_session: Session = Depends(get_db),
        ):
            # Execute your auth logic here
            ...
        return add_dependencies(Depends(dependency))(func)
    return decorator
```

The decorator can be used like so:
```python
@app.put("/users/{user_id}")
@authorize("users:write")
def update_user(*, user_id: int, user_update: UserUpdate):
    ...
```
