Skip to content

Commit e1d63a1

Browse files
committed
refactor: move to fastapi from django
1 parent 351fe0d commit e1d63a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+594
-1468
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.env
2+
.vscode
3+
.mypy_cache
4+
docker-stack.yml

backend/.gitignore

+2-235
Original file line numberDiff line numberDiff line change
@@ -1,235 +1,2 @@
1-
2-
# Created by https://www.toptal.com/developers/gitignore/api/python,django
3-
# Edit at https://www.toptal.com/developers/gitignore?templates=python,django
4-
5-
### Django ###
6-
*.log
7-
*.pot
8-
*.pyc
9-
__pycache__/
10-
local_settings.py
11-
db.sqlite3
12-
db.sqlite3-journal
13-
media
14-
15-
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
16-
# in your Git repository. Update and uncomment the following line accordingly.
17-
# <django-project-name>/staticfiles/
18-
19-
### Django.Python Stack ###
20-
# Byte-compiled / optimized / DLL files
21-
*.py[cod]
22-
*$py.class
23-
24-
# C extensions
25-
*.so
26-
27-
# Distribution / packaging
28-
.Python
29-
build/
30-
develop-eggs/
31-
dist/
32-
downloads/
33-
eggs/
34-
.eggs/
35-
parts/
36-
sdist/
37-
var/
38-
wheels/
39-
pip-wheel-metadata/
40-
share/python-wheels/
41-
*.egg-info/
42-
.installed.cfg
43-
*.egg
44-
MANIFEST
45-
46-
# PyInstaller
47-
# Usually these files are written by a python script from a template
48-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
49-
*.manifest
50-
*.spec
51-
52-
# Installer logs
53-
pip-log.txt
54-
pip-delete-this-directory.txt
55-
56-
# Unit test / coverage reports
57-
htmlcov/
58-
.tox/
59-
.nox/
60-
.coverage
61-
.coverage.*
62-
.cache
63-
nosetests.xml
64-
coverage.xml
65-
*.cover
66-
*.py,cover
67-
.hypothesis/
68-
.pytest_cache/
69-
pytestdebug.log
70-
71-
# Translations
72-
*.mo
73-
74-
# Django stuff:
75-
76-
# Flask stuff:
77-
instance/
78-
.webassets-cache
79-
80-
# Scrapy stuff:
81-
.scrapy
82-
83-
# Sphinx documentation
84-
docs/_build/
85-
doc/_build/
86-
87-
# PyBuilder
88-
target/
89-
90-
# Jupyter Notebook
91-
.ipynb_checkpoints
92-
93-
# IPython
94-
profile_default/
95-
ipython_config.py
96-
97-
# pyenv
98-
.python-version
99-
100-
# pipenv
101-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
102-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
103-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
104-
# install all needed dependencies.
105-
#Pipfile.lock
106-
107-
# poetry
108-
#poetry.lock
109-
110-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
111-
__pypackages__/
112-
113-
# Celery stuff
114-
celerybeat-schedule
115-
celerybeat.pid
116-
117-
# SageMath parsed files
118-
*.sage.py
119-
120-
# Environments
121-
# .env
122-
.env/
123-
.venv/
124-
env/
125-
venv/
126-
ENV/
127-
env.bak/
128-
venv.bak/
129-
pythonenv*
130-
131-
# Spyder project settings
132-
.spyderproject
133-
.spyproject
134-
135-
# Rope project settings
136-
.ropeproject
137-
138-
# mkdocs documentation
139-
/site
140-
141-
# mypy
142-
.mypy_cache/
143-
.dmypy.json
144-
dmypy.json
145-
146-
# Pyre type checker
147-
.pyre/
148-
149-
# pytype static type analyzer
150-
.pytype/
151-
152-
# operating system-related files
153-
# file properties cache/storage on macOS
154-
*.DS_Store
155-
# thumbnail cache on Windows
156-
Thumbs.db
157-
158-
# profiling data
159-
.prof
160-
161-
162-
### Python ###
163-
# Byte-compiled / optimized / DLL files
164-
165-
# C extensions
166-
167-
# Distribution / packaging
168-
169-
# PyInstaller
170-
# Usually these files are written by a python script from a template
171-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
172-
173-
# Installer logs
174-
175-
# Unit test / coverage reports
176-
177-
# Translations
178-
179-
# Django stuff:
180-
181-
# Flask stuff:
182-
183-
# Scrapy stuff:
184-
185-
# Sphinx documentation
186-
187-
# PyBuilder
188-
189-
# Jupyter Notebook
190-
191-
# IPython
192-
193-
# pyenv
194-
195-
# pipenv
196-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
197-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
198-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
199-
# install all needed dependencies.
200-
201-
# poetry
202-
203-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
204-
205-
# Celery stuff
206-
207-
# SageMath parsed files
208-
209-
# Environments
210-
# .env
211-
212-
# Spyder project settings
213-
214-
# Rope project settings
215-
216-
# mkdocs documentation
217-
218-
# mypy
219-
220-
# Pyre type checker
221-
222-
# pytype static type analyzer
223-
224-
# operating system-related files
225-
# file properties cache/storage on macOS
226-
# thumbnail cache on Windows
227-
228-
# profiling data
229-
230-
231-
# End of https://www.toptal.com/developers/gitignore/api/python,django
232-
233-
data/*
234-
.env
235-
.vscode/*
1+
__pycache__
2+
app.egg-info

backend/app/app/config.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from typing import List, Union
2+
3+
from pydantic import AnyHttpUrl, BaseSettings, validator
4+
5+
6+
class Settings(BaseSettings):
7+
API_STR: str = "/api"
8+
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
9+
10+
@validator("BACKEND_CORS_ORIGINS", pre=True)
11+
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
12+
if isinstance(v, str) and not v.startswith("["):
13+
return [i.strip() for i in v.split(",")]
14+
elif isinstance(v, (list, str)):
15+
return v
16+
raise ValueError(v)
17+
18+
PROJECT_NAME: str
19+
20+
class Config:
21+
case_sensitive = True
22+
23+
24+
settings = Settings()

backend/app/app/main.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from fastapi import FastAPI
2+
from fastapi.middleware.cors import CORSMiddleware
3+
4+
from app.config import settings
5+
from app.routes import sentence, text_complexity, tokens
6+
7+
app = FastAPI(
8+
title=settings.PROJECT_NAME,
9+
docs_url=f"{settings.API_STR}/docs",
10+
openapi_url=f"{settings.API_STR}/openapi.json",
11+
)
12+
13+
app.add_middleware(
14+
CORSMiddleware,
15+
allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
16+
allow_credentials=True,
17+
allow_methods=["*"],
18+
allow_headers=["*"],
19+
)
20+
app.include_router(tokens.router, prefix=settings.API_STR)
21+
app.include_router(sentence.router, prefix=settings.API_STR)
22+
app.include_router(text_complexity.router, prefix=settings.API_STR)

backend/app/app/routes/sentence.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from fastapi import APIRouter
2+
3+
router = APIRouter()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from fastapi import APIRouter
2+
3+
router = APIRouter()

backend/app/app/routes/tokens.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from fastapi import APIRouter
2+
3+
router = APIRouter()

backend/app/app/schemas.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from pydantic import BaseModel
2+
3+
4+
class Text(BaseModel):
5+
content: str
6+
7+
8+
class Token(BaseModel):
9+
form: str
10+
pos: str
11+
12+
13+
class Sentence(BaseModel):
14+
sentence_lenght: int
15+
verb_per_sentence: int

0 commit comments

Comments
 (0)