Skip to content

Commit 69681c1

Browse files
committed
initial commit
more clearer stucture add alembic autogenration sqlalchemy add pytest format remove useless code add base model remove unused code update dependency fix fix add migrate polish shell plus add alembic migrations format mv tifa.gif url to issue board polish globals fix static add socketio example fix test polish readme fix fix
0 parents  commit 69681c1

Some content is hidden

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

56 files changed

+4177
-0
lines changed

.flake8

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[flake8]
2+
max-line-length = 100
3+
exclude =
4+
.git,
5+
.eggs
6+
__pycache__,
7+
docs/source/conf.py,
8+
old,
9+
build,
10+
venv,
11+
migrations,
12+
ignore=E131,W503,E203

.gitignore

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
49+
# Translations
50+
*.mo
51+
*.pot
52+
53+
# Django stuff:
54+
*.log
55+
local_settings.py
56+
57+
# Flask stuff:
58+
instance/
59+
.webassets-cache
60+
61+
# Scrapy stuff:
62+
.scrapy
63+
64+
# Sphinx documentation
65+
docs/_build/
66+
67+
# PyBuilder
68+
target/
69+
70+
# Jupyter Notebook
71+
.ipynb_checkpoints
72+
73+
# pyenv
74+
.python-version
75+
76+
# celery beat schedule file
77+
celerybeat-schedule
78+
79+
# SageMath parsed files
80+
*.sage.py
81+
82+
# dotenv
83+
.env
84+
85+
# virtualenv
86+
.venv
87+
venv/
88+
ENV/
89+
90+
# Spyder project settings
91+
.spyderproject
92+
.spyproject
93+
94+
# Rope project settings
95+
.ropeproject
96+
97+
# mkdocs documentation
98+
/site
99+
100+
# mypy
101+
.mypy_cache/
102+
.idea
103+
config.yaml

.pre-commit-config.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
3+
- repo: https://github.com/ambv/black
4+
rev: 19.10b0
5+
hooks:
6+
- id: black
7+
language_version: python3.8
8+
9+
10+
- repo: https://github.com/pre-commit/pre-commit-hooks
11+
rev: v1.2.3
12+
hooks:
13+
- id: flake8

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 twocucao
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.PHONY: help
2+
.DEFAULT_GOAL := help
3+
4+
define PRINT_HELP_PYSCRIPT
5+
import re, sys
6+
7+
for line in sys.stdin:
8+
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
9+
if match:
10+
target, help = match.groups()
11+
print("%-30s %s" % (target, help))
12+
endef
13+
export PRINT_HELP_PYSCRIPT
14+
15+
help:
16+
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
17+
18+
start: ## start
19+
uvicorn tifa.app:current_app --reload
20+
21+
flake8: ## lint
22+
poetry run flake8 tifa
23+
24+
publish: ## publish package to pypi
25+
poetry publish --build
26+
27+
test: ## test
28+
python -m pytest tests
29+
30+
format: ## publish package to pypi
31+
black tifa
32+
black tests
33+
34+
dbinit:
35+
alembic init -t async ./migration

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Tifa
2+
3+
Yet another **opinionated** fastapi-start-kit with best practice
4+
5+
![tifa](https://user-images.githubusercontent.com/5625783/118087406-19244200-b3f8-11eb-839d-f8faf3044f2d.gif)
6+
7+
for my goddess -- Tifa
8+
9+
## Feature
10+
11+
1. Async! Async! Async!
12+
- web framework by fastapi
13+
- socket.io by python-socketio
14+
- async orm by sqlalchemy/alembic migration
15+
2. Much Less History Burden
16+
- newer sdk
17+
- newer python (3.9+)
18+
3. Best Practice
19+
- try automate every boring stuff
20+
- type hint
21+
- build with poetry
22+
23+
## Quick Setup
24+
25+
```bash
26+
poetry install
27+
28+
# db setup
29+
createuser tifa
30+
createdb tifa
31+
psql -c "alter user tifa with encrypted password 'tifa123';"
32+
psql -c "alter user tifa with superuser;"
33+
```
34+
35+
## Credits
36+
37+
1. https://github.com/ryanwang520/create-flask-skeleton
38+
2. https://github.com/tiangolo/full-stack-fastapi-postgresql
39+

migration/README

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration with an async dbapi.

migration/alembic.ini

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# path to migration scripts
5+
script_location = ./migrate
6+
7+
# template used to generate migration files
8+
# file_template = %%(rev)s_%%(slug)s
9+
10+
# sys.path path, will be prepended to sys.path if present.
11+
# defaults to the current working directory.
12+
prepend_sys_path = .
13+
14+
# timezone to use when rendering the date
15+
# within the migration file as well as the filename.
16+
# string value is passed to dateutil.tz.gettz()
17+
# leave blank for localtime
18+
# timezone =
19+
20+
# max length of characters to apply to the
21+
# "slug" field
22+
# truncate_slug_length = 40
23+
24+
# set to 'true' to run the environment during
25+
# the 'revision' command, regardless of autogenerate
26+
# revision_environment = false
27+
28+
# set to 'true' to allow .pyc and .pyo files without
29+
# a source .py file to be detected as revisions in the
30+
# versions/ directory
31+
# sourceless = false
32+
33+
# version location specification; this defaults
34+
# to ./migrate/versions. When using multiple version
35+
# directories, initial revisions must be specified with --version-path
36+
# version_locations = %(here)s/bar %(here)s/bat ./migrate/versions
37+
38+
# the output encoding used when revision files
39+
# are written from script.py.mako
40+
# output_encoding = utf-8
41+
42+
[post_write_hooks]
43+
# post_write_hooks defines scripts or Python functions that are run
44+
# on newly generated revision scripts. See the documentation for further
45+
# detail and examples
46+
47+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
48+
# hooks = black
49+
# black.type = console_scripts
50+
# black.entrypoint = black
51+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
52+
53+
# Logging configuration
54+
[loggers]
55+
keys = root,sqlalchemy,alembic
56+
57+
[handlers]
58+
keys = console
59+
60+
[formatters]
61+
keys = generic
62+
63+
[logger_root]
64+
level = WARN
65+
handlers = console
66+
qualname =
67+
68+
[logger_sqlalchemy]
69+
level = WARN
70+
handlers =
71+
qualname = sqlalchemy.engine
72+
73+
[logger_alembic]
74+
level = INFO
75+
handlers =
76+
qualname = alembic
77+
78+
[handler_console]
79+
class = StreamHandler
80+
args = (sys.stderr,)
81+
level = NOTSET
82+
formatter = generic
83+
84+
[formatter_generic]
85+
format = %(levelname)-5.5s [%(name)s] %(message)s
86+
datefmt = %H:%M:%S

0 commit comments

Comments
 (0)