•  


GitHub - marirs/fastapi-boilerplate: fastAPI boilerplate for API based access along with user management
Skip to content

fastAPI boilerplate for API based access along with user management

License

Notifications You must be signed in to change notification settings

marirs/fastapi-boilerplate

Folders and files

Name Name
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastAPI Biolerplate

A FastAPI project!

  • Every endpoint should be accessed by an API key
  • API key has roles, such a way that, access to appropriate endpoints is allowed or denied
  • Multiple endpoint project
  • User management to create new users, disable users, verify email accounts and then allow api access, etc...
  • Connects to MongoDB


A Rust version can be found here .


Requirements

  • fastAPI
  • Python 3.7+

Lib Requirements

  • UVLoop
  • re2

Database

  • MongoDB

Setting up

mkvirtualenv --python=/usr/bin/python3 fastapi-boilerplate
cd /path/to/project
setvirtualenvproject

Installing the requirements

pip install pipenv
pipenv install

OR

pip install -r requirements.txt

Creating the first user

$ ./first_user.py email@somemail.tld
Your API Key is: _hplIyYGpeVKc... (Do not loose this key as its not stored in the system)

Running the Project in Dev env

uvicorn server.main:app --reload

Project Structure

api/endpoints - handlers for all endpoint routes
core          - general components like settings, security, key validation, etc...
db            - db connection specific
db/crud       - CRUD for types from models
models        - pydantic models that used in crud or handlers

Docs

Accessing the "user" endpoint with non superuser account

$ curl -H'x-api-key: -OWN3pNZ6FsaPppPqsyeuF6sxe' -H'x-email-id: e@mail.tld' http://127.0.0.1:8000/api/user/ 

{
    "created_at": "2019-11-01T03:21:02.868000",
    "updated_at": "2019-11-06T03:22:01.045000",
    "email": "e@mail.tld"
}

Accessing the "user" endpoint with superuser account

$ curl -H'x-api-key: -OWN3pNZ6FsaPppPqsyeuF6sxe' -H'x-email-id: e@mail.tld' http://127.0.0.1:8000/api/user/ 
{
    "total_users": 1,
    "users": [
        {
            "created_at": "2019-11-01T03:21:02.868000",
            "updated_at": "2019-11-06T03:22:01.045000",
            "email": "e@mail.tld",
            "endpoint_access": [
                "user"
            ],
            "is_superuser": true,
            "is_active": true,
            "disabled": false,
            "hashed_api_key": "$2b$12$DJ2D249xR4MY.aeTODeq5OasBR8TUoxknjxX6WqLf1QoG1k7VWQim",
            "salt": "$2b$12$lJ937UATRjcCU4.kk0HYZ."
        }
    ]
}

Accessing the "hello" endpoint

$ curl -H'x-api-key: -OWN3pNZ6FsaPppPqsyeuF6sxe' -H'x-email-id: e@mail.tld' http://127.0.0.1:8000/api/hello/ 

"Hello World"

Verify an email account of an added API user account

$ curl http://127.0.0.1:8000/api/user/verify?email=marirs@gmail.com

{
    "detail": "e@mail.tld is now verified! You can start using your API key."
}

Disabling an email account

$ curl  -H'x-api-key: -OWN3pNZ6FsaPppPqsyeuF6sxe' -H'x-email-id: e@mail.tld' http://localhost:8000/api/user/disable?email=someone@gmail.com

{
    "detail": "someone@gmail.com is disabled!"
}

Initial Author: Sriram

Releases

No releases published

Packages

No packages published

Languages

- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본