Metadata-Version: 2.4
Name: authfast
Version: 0.1.0
Summary: A tiny authentication toolkit for FastAPI.
Author: AuthFast contributors
License: MIT License
        
        Copyright (c) 2026 AuthFast contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: auth,authentication,fastapi,sessions,sqlalchemy
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Web Environment
Classifier: Framework :: FastAPI
Classifier: Framework :: Pydantic :: 2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Session
Classifier: Topic :: Security
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: aiosqlite>=0.19.0
Requires-Dist: email-validator>=2.0.0
Requires-Dist: fastapi>=0.110.0
Requires-Dist: pwdlib[argon2]>=0.2.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: pyjwt>=2.8.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: sqlalchemy>=2.0.0
Requires-Dist: typer>=0.12.0
Provides-Extra: all
Requires-Dist: asyncmy>=0.2.9; extra == 'all'
Requires-Dist: asyncpg>=0.29.0; extra == 'all'
Provides-Extra: mysql
Requires-Dist: asyncmy>=0.2.9; extra == 'mysql'
Provides-Extra: postgres
Requires-Dist: asyncpg>=0.29.0; extra == 'postgres'
Description-Content-Type: text/markdown

# AuthFast

A tiny authentication toolkit for FastAPI.

AuthFast gives FastAPI apps a simple way to add authentication without building the same routes, sessions, and database setup from scratch.

## Install

```bash
pip install authfast
```

Default install supports SQLite. For production databases, install the matching driver extra:

```bash
pip install "authfast[postgres]"
pip install "authfast[mysql]"
pip install "authfast[all]"
```

Supported database targets:

- SQLite: `sqlite:///./app.db` or `sqlite+aiosqlite:///./app.db`
- PostgreSQL, Neon, Supabase Postgres: `postgresql://...` or `postgresql+asyncpg://...`
- MySQL/MariaDB: `mysql://...` or `mysql+asyncmy://...`

## Create `auth.py`

Create `.env` next to `auth.py`:

```env
AUTHFAST_SECRET_KEY=change-this-secret-for-local-development
```

```python
from authfast import AuthFast

auth = AuthFast(
    database="sqlite:///./app.db",
    email_and_password={
        "enabled": True,
    },
)
```

## Set Up The Database

```bash
authfast setup
```

The CLI looks for `auth.py` in `./`, `./app`, `./lib`, `./src`, `./src/app`, and `./src/lib`.
For SQLite, the relative database path is resolved from the directory where you run the command or server. Run `authfast setup` and `uvicorn` from the same project root.

Use a custom path:

```bash
authfast setup --config examples/basic/auth.py
```

Drop and recreate AuthFast tables:

```bash
authfast setup --force
```

## Mount Routes

```python
from fastapi import FastAPI
from auth import auth

app = FastAPI()
app.include_router(auth.router)


@app.get("/protected")
async def protected(user=auth.user()):
    return {"id": user.id, "name": user.name, "email": user.email}
```

## Use The API

Sign up:

```bash
curl -X POST http://127.0.0.1:8000/auth/sign-up/email \
  -H "Content-Type: application/json" \
  -d '{"name":"Dev","email":"dev@example.com","password":"secret123"}'
```

Log in:

```bash
curl -X POST http://127.0.0.1:8000/auth/sign-in/email \
  -H "Content-Type: application/json" \
  -d '{"email":"dev@example.com","password":"secret123"}'
```

Use the session cookie or returned bearer token:

```bash
curl http://127.0.0.1:8000/auth/me \
  -H "Authorization: Bearer <access_token>"
```

## Routes

- `POST /auth/sign-up/email`
- `POST /auth/sign-in/email`
- `POST /auth/sign-out`
- `POST /auth/signup`
- `POST /auth/login`
- `POST /auth/logout`
- `GET /auth/me`
- `GET /auth/session`

## Example

From the project root:

```bash
authfast setup --config examples/basic/auth.py
uvicorn examples.basic.main:app --reload
```

Or from inside `examples/basic`:

```bash
authfast setup --config auth.py
uvicorn main:app --reload
```

Keep `setup` and `uvicorn` in the same working directory when using the example SQLite URL, because `./app.db` is resolved from the current directory.

## Reference

See [docs/api-reference/index.mdx](docs/api-reference/index.mdx).
