Git Product home page Git Product logo

fastapi-beanie-jwt's Introduction

fastapi-beanie-jwt

Sample FastAPI server with JWT auth and Beanie ODM

Intro

This starter app provides a basic account API on top of a MongoDB store with the following features:

  • Registration
  • Email verification
  • Password reset
  • JWT auth login and refresh
  • User model CRUD

It's built on top of these libraries to provide those features:

Setup

This codebase was written for Python 3.9 and above. Don't forget about a venv as well. The python commands below assume you're pointing to your desired Python3 target.

First we'll need to install our requirements.

python -m pip install -r requirements.txt

Before we run the server, there is one config variable you'll need to generate the password salt. To do this, just run the script in this repo.

python gen_salt.py

There are other settings in config.py and the included .env file. Assuming you've changed the SALT value, everything should run as-is if there is a local MongoDB instance running (see below for a Docker solution). Any email links will be printed to the console by default.

Run

This sample uses uvicorn as our ASGI web server. This allows us to run our server code in a much more robust and configurable environment than the development server. For example, ASGI servers let you run multiple workers that recycle themselves after a set amount of time or number of requests.

uvicorn myserver.main:app --reload --port 8080

You're API should now be available at http://localhost:8080

Test

The sample app also comes with a test suite to get you started.

Make sure to install the requirements found in the test folder before trying to run the tests.

python -m pip install -r tests/requirements.txt

The tests need access to a MongoDB store that is emptied at the end of each test. The easiest way to do this is to run a Mongo container in the background.

docker run -d mongo

You can also connect to a remote server if you're running tests in a CI/CD pipeline. Just set the TEST_MONGO_URI in the environment. This value defaults to localhost and is only checked in the test suite. It should never use your MONGO_URI.

Then just run the test suite.

pytest

fastapi-beanie-jwt's People

Contributors

devdupont avatar flinz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.