-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/jbcodeforce/python-code
- Loading branch information
Showing
11 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# Pydantic | ||
|
||
[]() | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import requests | ||
|
||
|
||
with requests.get("http://localhost:8000", stream=True) as r: | ||
for chunk in r.iter_content(100): | ||
print(chunk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from fastapi import FastAPI | ||
from typing import Generator | ||
from fastapi.responses import StreamingResponse | ||
|
||
app = FastAPI() | ||
|
||
# coroutine which will suspend the execution if there is await or yield | ||
# yield creates an asynchronous generator, which we iterate over with async for. | ||
async def fake_video_streamer(): | ||
for i in range(10): | ||
yield b"some fake video bytes" | ||
|
||
# another example | ||
# A simple method to open the file and get the data | ||
async def get_data_from_file(file_path: str) -> Generator: | ||
with open(file=file_path, mode="rb") as file_like: | ||
yield file_like.read() | ||
|
||
@app.get("/") | ||
async def main(): | ||
return StreamingResponse(content=fake_video_streamer(),media_type="text/media") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uvicorn server:app --port 8000 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.