https://github.com/seapagan/fastapi-users-example
Example FastAPI app using 'fastapi-users' for Authentication
https://github.com/seapagan/fastapi-users-example
async fastapi fastapi-users python python3 sqlalchemy
Last synced: 8 months ago
JSON representation
Example FastAPI app using 'fastapi-users' for Authentication
- Host: GitHub
- URL: https://github.com/seapagan/fastapi-users-example
- Owner: seapagan
- License: mit
- Created: 2025-02-16T09:43:59.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-02-16T10:27:22.000Z (11 months ago)
- Last Synced: 2025-02-16T10:28:44.690Z (11 months ago)
- Topics: async, fastapi, fastapi-users, python, python3, sqlalchemy
- Language: Python
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FastAPI Auth Example
This is an example of how to use [FastAPI](https://fastapi.tiangolo.com/) with
JWT authentication, using the
[fastapi_users](https://fastapi-users.github.io/fastapi-users/) library. It also
has `async` database access using [SQLAlchemy](https://www.sqlalchemy.org/)
Currently uses **SQLite** as the database, but can be easily changed to any
other database. It largely follows the example in the fastapi-users
documentation, however I have laid the project out in a way that I find more
readable and maintainable.
We use the [database
strategy](https://fastapi-users.github.io/fastapi-users/latest/configuration/authentication/strategies/database/)
instead of the default `jwt` strategy, as it allows us to invalidate tokens on
the server side. For the Transport, we use the
[Bearer](https://fastapi-users.github.io/fastapi-users/latest/configuration/authentication/transports/bearer/)
strategy where the token is sent in the `Authorization` header.
The project uses [uv](https://docs.astral.sh/uv/) to manage the dependencies. To
install the dependencies and switch to the virtual environment, run:
```bash
uv sync
source .venv/bin/activate # On Windows, use .venv\Scripts\activate
```
Now you can run the project with:
```bash
python main.py
```
> [!NOTE]
>
> The above uses the `--reload` option, so the server will restart whenever you
> change a file. This is useful for development, but not recommended for
> production.
The project will be available at `http://localhost:8000`.
You can access the API documentation at `http://localhost:8000/docs` (or
`http://localhost:8000/redoc` if you prefer that).