├── requirements.txt ├── .vscode └── extensions.json ├── .devcontainer ├── Dockerfile └── devcontainer.json ├── api └── main.py ├── README.md └── .gitignore /requirements.txt: -------------------------------------------------------------------------------- 1 | fastapi -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ms-python.python" 4 | ] 5 | } -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG VARIANT=bullseye 2 | FROM --platform=amd64 mcr.microsoft.com/devcontainers/python:${VARIANT} -------------------------------------------------------------------------------- /api/main.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | import fastapi 4 | 5 | app = fastapi.FastAPI() 6 | 7 | @app.get("/generate_name") 8 | async def generate_name(): 9 | names = ["Minnie", "Margaret", "Myrtle", "Noa", "Nadia"] 10 | random_name = random.choice(names) 11 | return {"name": random_name} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple FastAPI Playground 2 | 3 | This repository includes a very simple Python FastAPI HTTP API, made for demonstration purposes only. 4 | 5 | ## Local development 6 | 7 | 1. Open this repository in Github Codespaces or VS Code with Remote Dev Containers extension. 8 | 9 | 2. Run the development server: 10 | 11 | ```shell 12 | fastapi dev api/main.py 13 | ``` 14 | 15 | 3. Click ['http://127.0.0.1:8000'](http://127.0.0.1:8000) in the terminal, which should open the website in a new tab. 16 | 4. Append `/docs` or `/generate_name` to the end of the URL. 17 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Simple FastAPI Playground", 3 | "image": "mcr.microsoft.com/devcontainers/python:3.12", 4 | "forwardPorts": [8000], 5 | "customizations": { 6 | "vscode": { 7 | "extensions": [ 8 | "ms-python.python", 9 | "ms-python.black-formatter" 10 | ], 11 | "settings": { 12 | "python.defaultInterpreterPath": "/usr/local/bin/python", 13 | "python.linting.enabled": true, 14 | "[python]": { 15 | "editor.formatOnSave": true, 16 | "editor.codeActionsOnSave": { 17 | "source.fixAll": "explicit" 18 | }, 19 | "editor.defaultFormatter": "ms-python.black-formatter" 20 | }, 21 | "python.formatting.provider": "black", 22 | "files.exclude": { 23 | "**/*.coverage": true, 24 | ".ruff_cache": true, 25 | ".pytest_cache": true 26 | } 27 | } 28 | } 29 | }, 30 | "postCreateCommand": "pip3 install --user -r requirements.txt", 31 | "remoteUser": "vscode" 32 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 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 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | 53 | # Translations 54 | *.mo 55 | *.pot 56 | 57 | # Django stuff: 58 | *.log 59 | local_settings.py 60 | db.sqlite3 61 | 62 | # Flask stuff: 63 | instance/ 64 | .webassets-cache 65 | 66 | # Scrapy stuff: 67 | .scrapy 68 | 69 | # Sphinx documentation 70 | docs/_build/ 71 | 72 | # PyBuilder 73 | target/ 74 | 75 | # Jupyter Notebook 76 | .ipynb_checkpoints 77 | 78 | # IPython 79 | profile_default/ 80 | ipython_config.py 81 | 82 | # pyenv 83 | .python-version 84 | 85 | # pipenv 86 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 87 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 88 | # having no cross-platform support, pipenv may install dependencies that don’t work, or not 89 | # install all needed dependencies. 90 | #Pipfile.lock 91 | 92 | # celery beat schedule file 93 | celerybeat-schedule 94 | 95 | # SageMath parsed files 96 | *.sage.py 97 | 98 | # Environments 99 | .env 100 | .venv 101 | env/ 102 | venv/ 103 | ENV/ 104 | env.bak/ 105 | venv.bak/ 106 | 107 | # Spyder project settings 108 | .spyderproject 109 | .spyproject 110 | 111 | # Rope project settings 112 | .ropeproject 113 | 114 | # mkdocs documentation 115 | /site 116 | 117 | # mypy 118 | .mypy_cache/ 119 | .dmypy.json 120 | dmypy.json 121 | 122 | # Pyre type checker 123 | .pyre/ 124 | 125 | # Azure Functions artifacts 126 | bin 127 | obj 128 | appsettings.json 129 | 130 | # Azurite artifacts 131 | __blobstorage__ 132 | __queuestorage__ 133 | __azurite_db*__.json 134 | .python_packages 135 | .azure 136 | --------------------------------------------------------------------------------