Skip to main content

FastAPI Users - Database adapter for Tortoise ORM

Project description

Fastapi-users-tortoise

Tortoise orm database adapter for fastapi-users v10 and above.

Installation

pip install fastapi-users-tortoise

Usage

# models.py

from fastapi_users_tortoise import TortoiseBaseUserAccountModelUUID, TortoiseUserDatabase, TortoiseBaseUserOAuthAccountModelUUID
from fastapi_users_tortoise.access_token import TortoiseBaseAccessTokenModel, TortoiseAccessTokenDatabase
from tortoise import fields

class User(TortoiseBaseUserAccountModelUUID):
    full_name = fields.CharField(max_length=255, null=True)
    short_name = fields.CharField(max_length=255, null=True)

class OAuthAccount(TortoiseBaseUserOAuthAccountModelUUID):
    pass

async def get_user_db():
    yield TortoiseUserDatabase(User)


# If you need to store access token to the database

class AccessToken(TortoiseBaseAccessTokenModel):
    pass

async def get_access_token_db():
    yield TortoiseAccessTokenDatabase(AccessToken)

Note: Until the documentation is ready you can use the fastapi-users sqlalchemy setup guide as reference.

Development

Setup environment

You should create a virtual environment and activate it:

python -m venv venv/
source venv/bin/activate

And then install the development dependencies:

pip install -r requirements.dev.txt

Run unit tests

You can run all the tests with:

make test

Alternatively, you can run pytest yourself:

pytest

There are quite a few unit tests, so you might run into ulimit issues where there are too many open file descriptors. You may be able to set a new, higher limit temporarily with:

ulimit -n 2048

Format the code

Execute the following command to apply isort and black formatting:

make format

TODO

  • Improve type hint and generics usage

License

This project is licensed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi-users-tortoise-0.1.0.tar.gz (8.6 kB view hashes)

Uploaded Source

Built Distribution

fastapi_users_tortoise-0.1.0-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page