Inital commit

This commit is contained in:
Jimmy 2021-09-12 20:45:44 +12:00
commit 6ee4d38c06
12 changed files with 183 additions and 0 deletions

0
.env.sample Normal file
View File

64
.gitignore vendored Normal file
View File

@ -0,0 +1,64 @@
.vscode/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# mypy
.mypy_cache/
.dmypy.json
dmypy.json

6
Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8-slim
ENV DOCKER=1
COPY ./requirements.txt /
RUN pip install -r /requirements.txt && rm /requirements.txt
COPY ./app /app/app

21
LICENSE Normal file
View File

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

23
Pipfile Normal file
View File

@ -0,0 +1,23 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
fastapi = "*"
fastapi-responses = "*"
uvicorn = {extras = ["standard"], version = "*"}
[dev-packages]
# pytest = "*"
# requests = "*"
# pytest-asyncio = "*"
# black = "*"
# mypy = "*"
[requires]
python_version = "3.8"
[scripts]
test = "pytest app/test/test_main.py -s"
dev = "uvicorn app.main:app --reload"

18
README.md Normal file
View File

@ -0,0 +1,18 @@
# FastApi Template
```pipenv sync```
```pipenv sync --dev```
## Run local dev server
```pipenv run dev```
## Run Pytest
```pipenv run test```
## Run in Docker
```pipenv lock -r requirements.txt```
```sudo docker-compose up --build```

0
app/__init__.py Normal file
View File

8
app/main.py Executable file
View File

@ -0,0 +1,8 @@
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def read_main():
return {"msg": "Hello World"}

4
app/test/__init__.py Normal file
View File

@ -0,0 +1,4 @@
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

10
app/test/test_main.py Normal file
View File

@ -0,0 +1,10 @@
from fastapi.testclient import TestClient
import app.main
client = TestClient(app.main.app)
def test_read_main():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"msg": "Hello World"}

13
docker-compose.yml Normal file
View File

@ -0,0 +1,13 @@
version: '3.7'
services:
app:
build: .
env_file:
- .env
ports:
- 8000:80
tty: true
stdin_open: true

16
requirements.txt Normal file
View File

@ -0,0 +1,16 @@
-i https://pypi.org/simple
asgiref==3.4.1; python_version >= '3.6'
click==8.0.1; python_version >= '3.6'
fastapi-responses==0.2.1
fastapi==0.68.1
h11==0.12.0; python_version >= '3.6'
httptools==0.2.0
pydantic==1.8.2; python_full_version >= '3.6.1'
python-dotenv==0.19.0
pyyaml==5.4.1
starlette==0.14.2; python_version >= '3.6'
typing-extensions==3.10.0.2
uvicorn[standard]==0.15.0
uvloop==0.16.0
watchgod==0.7
websockets==10.0