Skip to content

Commit cd48409

Browse files
committed
initial setup
1 parent c7cb402 commit cd48409

File tree

8 files changed

+216
-0
lines changed

8 files changed

+216
-0
lines changed

.funcignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.git*
2+
.vscode
3+
__azurite_db*__.json
4+
__blobstorage__
5+
__queuestorage__
6+
local.settings.json
7+
test
8+
.venv

.gitignore

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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+
.azure_function_fastapi_venv
104+
ENV/
105+
env.bak/
106+
venv.bak/
107+
108+
# Spyder project settings
109+
.spyderproject
110+
.spyproject
111+
112+
# Rope project settings
113+
.ropeproject
114+
115+
# mkdocs documentation
116+
/site
117+
118+
# mypy
119+
.mypy_cache/
120+
.dmypy.json
121+
dmypy.json
122+
123+
# Pyre type checker
124+
.pyre/
125+
126+
# Azure Functions artifacts
127+
bin
128+
obj
129+
appsettings.json
130+
local.settings.json
131+
132+
# Azurite artifacts
133+
__blobstorage__
134+
__queuestorage__
135+
__azurite_db*__.json
136+
.python_packages

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
11
# azure-function-fastapi
22
deploy python fastapi on azure function
3+
4+
# local development (fastapi)
5+
6+
## venv
7+
```bash
8+
# create virtual environment
9+
python3 -m venv .azure_function_fastapi_venv
10+
11+
# activate virtual environment
12+
source .azure_function_fastapi_venv/bin/activate
13+
```
14+
15+
## run fast api project
16+
17+
```bash
18+
# install packages
19+
pip3 install -r requirements.txt
20+
21+
# run project with uvicorn
22+
uvicorn "fastapi_project.main:app" --reload --port=8000
23+
```

fastapi_project/__init__.py

Whitespace-only changes.

fastapi_project/api/root_index.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from fastapi import APIRouter, status, Request
2+
from fastapi.responses import JSONResponse
3+
4+
# Create a FastAPI app
5+
router = APIRouter()
6+
7+
# root index
8+
@router.get("/")
9+
async def root_index(request: Request):
10+
data = {
11+
'message': 'azure function project is running'
12+
}
13+
return JSONResponse(content=data, status_code=status.HTTP_200_OK)
14+

fastapi_project/main.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from fastapi import FastAPI
2+
from dotenv import load_dotenv
3+
from fastapi.middleware.cors import CORSMiddleware
4+
from fastapi_project.api import root_index
5+
# Load .env file
6+
load_dotenv()
7+
8+
def create_application():
9+
application = FastAPI()
10+
11+
# Include routers
12+
application.include_router(root_index.router)
13+
14+
# Allow all origins (not recommended for production)
15+
# Replace the "*" with the actual frontend URL in production
16+
application.add_middleware(
17+
CORSMiddleware,
18+
allow_origins=["*"], # Replace ["*"] with your frontend URL in production
19+
allow_credentials=True,
20+
allow_methods=["GET", "POST", "PUT", "DELETE"],
21+
allow_headers=["*"],
22+
)
23+
24+
return application
25+
26+
app = create_application()

host.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"version": "2.0",
3+
"extensions": {
4+
"http": {
5+
"routePrefix": ""
6+
}
7+
}
8+
}

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
azure-functions
2+
fastapi
3+
python-dotenv

0 commit comments

Comments
 (0)