Skip to content

Commit

Permalink
add fastapi
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcodeforce committed Mar 23, 2024
1 parent 5df66da commit 6bf0155
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ kafka/kafka1/
kafka/zookeeper1/
web_data/imgur/images/
.env
**/.venv/
2 changes: 1 addition & 1 deletion Flask/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.7-alpine
FROM python:3.11-alpine
ADD . /code
WORKDIR /code
RUN pip install flask
Expand Down
28 changes: 28 additions & 0 deletions algorithms/park_walk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@


max_length = 0

def maxLengthPath(park,r,c):
max_length = 0
visited=[[]]
return maxLengthPathR(max_length,park,visited,r,c)

def maxLengthPathR(max_length,park,visited,r,c):
if r < 0 :
return 0
if c < 0:
return 0
if not park[r][c]:
return 0
visited[r][c]= True
if not visited[r][c+1]:
m1=maxLengthPathR(max_length,park,visited,r,c+1)
if m1>max_length:
max_length = m1
return max_length

print(maxLengthPath([[True,False,False]],0,0))
assert maxLengthPath([[False,False,False]],0,0) == 0
assert maxLengthPath([[True,False,False]],0,0) == 1
assert maxLengthPath([[True,True,False]],0,0) == 2
assert maxLengthPath([[True,True,False]],0,1) == 2
2 changes: 2 additions & 0 deletions docs/python/pydantic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Pydantic

18 changes: 18 additions & 0 deletions docs/python/web-rest-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Web Server and REST API

## [FastAPI](https://fastapi.tiangolo.com/#installation)

FastAPI is a web framework to build APIs. It needs the ASGI server like [uvicorn](https://www.uvicorn.org/).

```sh
uvicorn fastapi_main:app --reload
```

* Some URLs

```sh
http://127.0.0.1:8000/docs
http://127.0.0.1:8000/redoc
```

* [See full tutorial](https://fastapi.tiangolo.com/tutorial/)
7 changes: 7 additions & 0 deletions web-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.11-alpine
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt

EXPOSE 80
CMD ["uvicorn", "fastapi_main:app", "--host", "0.0.0.0", "--port", "80"]
15 changes: 15 additions & 0 deletions web-server/fastapi_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Union

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
3 changes: 3 additions & 0 deletions web-server/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
uvicorn[standard]
fastapi
pydantic

0 comments on commit 6bf0155

Please sign in to comment.