From 6ee4d38c06f8f5cb769c686e386b3cb47d746409 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Sun, 12 Sep 2021 20:45:44 +1200 Subject: [PATCH] Inital commit --- .env.sample | 0 .gitignore | 64 +++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 6 ++++ LICENSE | 21 ++++++++++++++ Pipfile | 23 ++++++++++++++++ README.md | 18 ++++++++++++ app/__init__.py | 0 app/main.py | 8 ++++++ app/test/__init__.py | 4 +++ app/test/test_main.py | 10 +++++++ docker-compose.yml | 13 +++++++++ requirements.txt | 16 +++++++++++ 12 files changed, 183 insertions(+) create mode 100644 .env.sample create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 Pipfile create mode 100644 README.md create mode 100644 app/__init__.py create mode 100755 app/main.py create mode 100644 app/test/__init__.py create mode 100644 app/test/test_main.py create mode 100644 docker-compose.yml create mode 100644 requirements.txt diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fbcfa91 --- /dev/null +++ b/.gitignore @@ -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 + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7c4604a --- /dev/null +++ b/Dockerfile @@ -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 \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d6a83d0 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..40af429 --- /dev/null +++ b/Pipfile @@ -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" diff --git a/README.md b/README.md new file mode 100644 index 0000000..a01d74a --- /dev/null +++ b/README.md @@ -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``` \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/main.py b/app/main.py new file mode 100755 index 0000000..4679aec --- /dev/null +++ b/app/main.py @@ -0,0 +1,8 @@ +from fastapi import FastAPI + +app = FastAPI() + + +@app.get("/") +async def read_main(): + return {"msg": "Hello World"} diff --git a/app/test/__init__.py b/app/test/__init__.py new file mode 100644 index 0000000..54fc925 --- /dev/null +++ b/app/test/__init__.py @@ -0,0 +1,4 @@ +import sys +import os + +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) diff --git a/app/test/test_main.py b/app/test/test_main.py new file mode 100644 index 0000000..394ffe6 --- /dev/null +++ b/app/test/test_main.py @@ -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"} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..87d315d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.7' + +services: + app: + build: . + env_file: + - .env + ports: + - 8000:80 + tty: true + stdin_open: true + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f109d54 --- /dev/null +++ b/requirements.txt @@ -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