feat: add example for starlette.io (#72)

* feat: add example for starlette.io

* feat: link additional documentation

* feat: dev hot reload docker command
This commit is contained in:
Anurag
2021-04-10 13:34:02 +05:30
committed by GitHub
parent c7dcf2619c
commit 50ee57407e
4 changed files with 195 additions and 0 deletions

159
examples/starlette/.gitignore vendored Normal file
View File

@@ -0,0 +1,159 @@
# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python
### Python ###
# 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
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coveage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
pytestdebug.log
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
doc/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# 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__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
pythonenv*
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# profiling data
.prof
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
.Python
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
.venv
pip-selfcheck.json
# End of https://www.toptal.com/developers/gitignore/api/python

View File

@@ -0,0 +1,7 @@
FROM tiangolo/uvicorn-gunicorn:python3.8-alpine3.10
LABEL maintainer="Sebastian Ramirez <tiangolo@gmail.com>"
RUN pip install --no-cache-dir starlette
COPY ./app /app

View File

@@ -0,0 +1,17 @@
# Python Starlette Example
This is a [Starlette](https://www.starlette.io/) app that serves a simple JSON response.
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new?template=https%3A%2F%2Fgithub.com%2Frailwayapp%2Fexamples%2Ftree%2Fmaster%2Fexamples%2Fstarlette)
## ✨ Features
- Python
- Starlette
## 💁‍♀️ How to use
- Build the docker image `docker build -t railway .`
- Start the container `docker run -d --name railway-test -p 80:80 railway`
- For auto restart in development `docker run -d -p 80:80 -v $(pwd):/app railway /start-reload.sh`
Note: Advance users may refer to [this](https://github.com/tiangolo/uvicorn-gunicorn-starlette-docker)

View File

@@ -0,0 +1,12 @@
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
async def homepage(request):
return JSONResponse({"Choo Choo": "Welcome to your Starlette app 🚅"})
app = Starlette(debug=True, routes=[
Route('/', homepage),
])