Skip to content

Commit b1fc247

Browse files
committed
feat: generated fastapi boilerplate with versioning and with folder structure.
1 parent 118b665 commit b1fc247

22 files changed

+803
-0
lines changed

.gitignore

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
# Project level files
2+
0.0.2
3+
alembic.ini
4+
changes_note.txt
5+
migrations/
6+
.dbdata/
7+
app.dp
8+
9+
# Byte-compiled / optimized / DLL files
10+
__pycache__/
11+
*.py[cod]
12+
*$py.class
13+
14+
# Backup files #
15+
*.bak
16+
17+
# C extensions
18+
*.so
19+
20+
# MacOS stuff
21+
**/.DS_Store
22+
23+
# Docker ignore
24+
.dockerignore
25+
26+
# Distribution / packaging
27+
.Python
28+
build/
29+
develop-eggs/
30+
dist/
31+
downloads/
32+
eggs/
33+
.eggs/
34+
lib/
35+
lib64/
36+
parts/
37+
sdist/
38+
var/
39+
wheels/
40+
share/python-wheels/
41+
*.egg-info/
42+
.installed.cfg
43+
*.egg
44+
MANIFEST
45+
flask_monitoringdashboard.db
46+
47+
# PyInstaller
48+
# Usually these files are written by a python script from a template
49+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
50+
*.manifest
51+
*.spec
52+
53+
# Installer logs
54+
pip-log.txt
55+
pip-delete-this-directory.txt
56+
57+
# Unit test / coverage reports
58+
htmlcov/
59+
.tox/
60+
.nox/
61+
.coverage
62+
.coverage.*
63+
.cache
64+
nosetests.xml
65+
coverage.xml
66+
*.cover
67+
*.py,cover
68+
.hypothesis/
69+
.pytest_cache/
70+
cover/
71+
72+
# Translations
73+
*.mo
74+
*.pot
75+
76+
# Django stuff:
77+
*.log
78+
local_settings.py
79+
db.sqlite3
80+
db.sqlite3-journal
81+
*.pot
82+
*.pyc
83+
__pycache__
84+
db.sqlite3
85+
media
86+
87+
#FastAPI stuff:
88+
.pytest_cache
89+
htmlcov
90+
dist
91+
site
92+
.coverage
93+
coverage.xml
94+
.netlify
95+
test.db
96+
log.txt
97+
docs_build
98+
docs.zip
99+
archive.zip
100+
101+
102+
# Flask stuff:
103+
# instance/
104+
.webassets-cache
105+
106+
# Scrapy stuff:
107+
.scrapy
108+
109+
# Sphinx documentation
110+
docs/_build/
111+
112+
# PyBuilder
113+
.pybuilder/
114+
target/
115+
116+
# Jupyter Notebook
117+
.ipynb_checkpoints
118+
119+
# Python #
120+
*.py[cod]
121+
*$py.class
122+
123+
# IPython
124+
profile_default/
125+
ipython_config.py
126+
127+
# pyenv
128+
# For a library or package, you might want to ignore these files since the code is
129+
# intended to run in multiple environments; otherwise, check them in:
130+
# .python-version
131+
132+
# pipenv
133+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
134+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
135+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
136+
# install all needed dependencies.
137+
#Pipfile.lock
138+
139+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
140+
__pypackages__/
141+
142+
# Celery stuff
143+
celerybeat-schedule
144+
celerybeat.pid
145+
146+
# SageMath parsed files
147+
*.sage.py
148+
149+
# Environments
150+
.env
151+
.venv/
152+
env/
153+
venv/
154+
ENV/
155+
env.bak/
156+
venv.bak/
157+
158+
# Spyder project settings
159+
.spyderproject
160+
.spyproject
161+
162+
# Rope project settings
163+
.ropeproject
164+
165+
# mkdocs documentation
166+
/site
167+
168+
# mypy
169+
.mypy_cache/
170+
.dmypy.json
171+
dmypy.json
172+
173+
# Pyre type checker
174+
.pyre/
175+
176+
# pytype static type analyzer
177+
.pytype/
178+
179+
# Cython debug symbols
180+
cython_debug/
181+
182+
.vscode/*
183+
!.vscode/settings.json
184+
!.vscode/tasks.json
185+
!.vscode/launch.json
186+
!.vscode/extensions.json
187+
*.code-workspace
188+
189+
# Local History for Visual Studio Code
190+
.history/
191+
192+
# If you are using PyCharm #
193+
# User-specific stuff
194+
.idea/**/workspace.xml
195+
.idea/**/tasks.xml
196+
.idea/**/usage.statistics.xml
197+
.idea/**/dictionaries
198+
.idea/**/shelf
199+
200+
# AWS User-specific
201+
.idea/**/aws.xml
202+
203+
# Generated files
204+
.idea/**/contentModel.xml
205+
206+
# Sensitive or high-churn files
207+
.idea/**/dataSources/
208+
.idea/**/dataSources.ids
209+
.idea/**/dataSources.local.xml
210+
.idea/**/sqlDataSources.xml
211+
.idea/**/dynamic.xml
212+
.idea/**/uiDesigner.xml
213+
.idea/**/dbnavigator.xml
214+
215+
# Gradle
216+
.idea/**/gradle.xml
217+
.idea/**/libraries
218+
219+
# File-based project format
220+
*.iws
221+
222+
# JIRA plugin
223+
atlassian-ide-plugin.xml
224+
225+
# Distribution / packaging
226+
.Python build/
227+
develop-eggs/
228+
dist/
229+
downloads/
230+
eggs/
231+
.eggs/
232+
lib/
233+
lib64/
234+
parts/
235+
sdist/
236+
var/
237+
wheels/
238+
*.egg-info/
239+
.installed.cfg
240+
*.egg
241+
*.manifest
242+
*.spec
243+
244+
# Installer logs
245+
pip-log.txt
246+
pip-delete-this-directory.txt
247+
248+
# Unit test / coverage reports
249+
htmlcov/
250+
.tox/
251+
.coverage
252+
.coverage.*
253+
.cache
254+
.pytest_cache/
255+
nosetests.xml
256+
coverage.xml
257+
*.cover
258+
.hypothesis/
259+
260+
# mkdocs documentation
261+
/site
262+
263+
# mypy
264+
.mypy_cache/
265+
266+
# .key
267+
SECRET.key

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# NewsPicking-Backend
2+
3+
## 🛠 Skills
4+
Python, Fask-API, Swagger Doc, Html and Java Scripts.
5+
6+
## Install + configure the project
7+
8+
### 1. Linux
9+
```
10+
# Create python virtual environment
11+
python3 -m venv venv
12+
13+
# Activate the python virtual environment
14+
source venv/bin/activate
15+
16+
# Install the requirements for the project into the virtual environment
17+
pip install -r requirements.txt
18+
19+
# Install the dependencies of Fast API
20+
pip install "fastapi[all]"
21+
22+
# Upgrade pip version
23+
python -m pip install --upgrade pip==22.1.2
24+
```
25+
### 2. Windows
26+
```
27+
# Create python virtual environment
28+
conda create --name venv python=3.10.12
29+
30+
# Activate the python virtual environment
31+
conda activate venv
32+
33+
# Install the requirements for the project into the virtual environment in the following sequence:
34+
pip install -r requirements.txt
35+
36+
# Install the dependencies of Fast API
37+
pip install "fastapi[all]"
38+
39+
# Upgrade pip version
40+
python -m pip install --upgrade pip==22.1.2
41+
```
42+
43+
## Use the alembic to Upgrade/Downgrade the database in the FastAPI
44+
Note: Because by default Fastapi is provide only initial migrations. It doesn't support the upgrade and downgrade the database.
45+
so,to perform automatic migrations follow the following steps:
46+
47+
1. # To create Migration folder
48+
python -m alembic init migrations
49+
50+
2. ## update the Migrations>>env.py file o auto migrate the database.
51+
from models import Base
52+
target_database = Base.metadata
53+
54+
4. # Perform the initial migrations
55+
alembic revision --autogenerate -m 'initials'
56+
57+
5. # Apply the changes into the database (upgrade the database)
58+
alembic upgrade head
59+
# To downgrade the database if required
60+
alembic downgrade -1
61+
62+
## Run the server in development mode
63+
64+
Add environment variables (given in .env) by running following command in cmd/terminal:
65+
66+
Run the server
67+
```
68+
python asgi.py
69+
```
70+
Browse Swagger API Doc at: http://localhost:8000/docs
71+
Browse Redoc at: http://localhost:8000/redoc
72+
73+
## Release History
74+
75+
* 0.1
76+
* Work in progress

apps/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from fastapi import FastAPI
2+
from fastapi_versioning import VersionedFastAPI
3+
4+
from apps.api.auth.v1.view import router
5+
from apps.api.auth.v2.view import authrouter
6+
from config import cors
7+
8+
# Create app object and add routes
9+
app = FastAPI(title="Python FastAPI boilerplate", middleware=cors.middleware)
10+
11+
# define router for different version
12+
app.include_router(router, prefix="/v1", tags=["v1"]) # router for version 1
13+
app.include_router(authrouter, prefix="/v2", tags=["v2"]) # router for version 2
14+
15+
# # # Define version to specify version related API's.
16+
app = VersionedFastAPI(app, version_format="{major}", prefix_format="/v{major}", enable_latest=True)

apps/api/auth/method.py

Whitespace-only changes.

apps/api/auth/response.py

Whitespace-only changes.

apps/api/auth/service.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from apps.utils.standard_response import StandardResponse
2+
from fastapi import status
3+
from apps.constant import constant
4+
5+
def get_str_name(name: str):
6+
if name is not None:
7+
return StandardResponse(
8+
True, status.HTTP_200_OK, {"success": "Welcome"},
9+
constant.STATUS_SUCCESS
10+
)
11+
else:
12+
return StandardResponse(
13+
True, status.HTTP_400_BAD_REQUEST, {"success": "Error"},
14+
constant.STATUS_ERROR
15+
)

apps/api/auth/test.py

Whitespace-only changes.

0 commit comments

Comments
 (0)