├── README.md ├── main.py ├── requirements.txt ├── template ├── __init__.py ├── __pycache__ │ └── __init__.cpython-37.pyc ├── ctrls │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc │ │ └── users.cpython-37.pyc │ └── users.py ├── logic │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc │ │ └── user_service.cpython-37.pyc │ └── user_service.py └── models │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-37.pyc │ └── user.cpython-37.pyc │ └── user.py ├── test-requirements.txt └── tests └── __init__.py /README.md: -------------------------------------------------------------------------------- 1 | # Python Template 2 | 3 | > A REST python template aimed for bigger applications using FastAPI and pydantic. 4 | 5 | During my last interviewing process at the beginning of 2022, I found that setting up an environment from scratch takes longer than I expected, 6 | and that finding documentation that wasn’t aimed for beginners or small projects takes even longer. 7 | For that reason I created this python template that has helped me speed the development setup using `FastAPI` and `pydantic`. 8 | 9 | You can read a full walkthrough of the template [here](https://towardsdatascience.com/python-project-template-for-a-quick-setup-d3ba1821e853). 10 | 11 | 12 | ## Example 13 | 14 | ![image](https://user-images.githubusercontent.com/15251650/189306708-82002b65-9106-488b-8cd1-d444b6759a56.png) 15 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | """docs: http://127.0.0.1:8000/docs""" 2 | import uvicorn 3 | from fastapi import FastAPI 4 | 5 | from template.ctrls import users 6 | 7 | 8 | app = FastAPI() 9 | app.include_router(users.router) 10 | 11 | 12 | if __name__ == '__main__': 13 | uvicorn.run('main:app') 14 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | fastapi 2 | uvicorn 3 | pydantic -------------------------------------------------------------------------------- /template/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirYeh/PythonTemplate/9b205a20ea236eab442976fd1c8fef681bd88f43/template/__init__.py -------------------------------------------------------------------------------- /template/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirYeh/PythonTemplate/9b205a20ea236eab442976fd1c8fef681bd88f43/template/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /template/ctrls/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirYeh/PythonTemplate/9b205a20ea236eab442976fd1c8fef681bd88f43/template/ctrls/__init__.py -------------------------------------------------------------------------------- /template/ctrls/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirYeh/PythonTemplate/9b205a20ea236eab442976fd1c8fef681bd88f43/template/ctrls/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /template/ctrls/__pycache__/users.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirYeh/PythonTemplate/9b205a20ea236eab442976fd1c8fef681bd88f43/template/ctrls/__pycache__/users.cpython-37.pyc -------------------------------------------------------------------------------- /template/ctrls/users.py: -------------------------------------------------------------------------------- 1 | from fastapi import APIRouter 2 | 3 | from template.logic.user_service import UserService 4 | from template.models.user import User 5 | 6 | 7 | router = APIRouter(prefix='/users') 8 | user_service = UserService() 9 | 10 | 11 | @router.post("/") 12 | async def greet(user: User) -> str: 13 | return user_service.greet(user) 14 | -------------------------------------------------------------------------------- /template/logic/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirYeh/PythonTemplate/9b205a20ea236eab442976fd1c8fef681bd88f43/template/logic/__init__.py -------------------------------------------------------------------------------- /template/logic/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirYeh/PythonTemplate/9b205a20ea236eab442976fd1c8fef681bd88f43/template/logic/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /template/logic/__pycache__/user_service.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirYeh/PythonTemplate/9b205a20ea236eab442976fd1c8fef681bd88f43/template/logic/__pycache__/user_service.cpython-37.pyc -------------------------------------------------------------------------------- /template/logic/user_service.py: -------------------------------------------------------------------------------- 1 | from template.models.user import User 2 | 3 | 4 | class UserService: 5 | 6 | @staticmethod 7 | def greet(user: User) -> str: 8 | return f'Hey {user.name.title()}!' 9 | -------------------------------------------------------------------------------- /template/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirYeh/PythonTemplate/9b205a20ea236eab442976fd1c8fef681bd88f43/template/models/__init__.py -------------------------------------------------------------------------------- /template/models/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirYeh/PythonTemplate/9b205a20ea236eab442976fd1c8fef681bd88f43/template/models/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /template/models/__pycache__/user.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirYeh/PythonTemplate/9b205a20ea236eab442976fd1c8fef681bd88f43/template/models/__pycache__/user.cpython-37.pyc -------------------------------------------------------------------------------- /template/models/user.py: -------------------------------------------------------------------------------- 1 | 2 | from pydantic import BaseModel 3 | 4 | 5 | class User(BaseModel): 6 | name: str 7 | -------------------------------------------------------------------------------- /test-requirements.txt: -------------------------------------------------------------------------------- 1 | pytest -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MirYeh/PythonTemplate/9b205a20ea236eab442976fd1c8fef681bd88f43/tests/__init__.py --------------------------------------------------------------------------------