Skip to content

Commit 257c191

Browse files
authored
Merge branch 'master' into python-314
2 parents ec2ce20 + ddcd360 commit 257c191

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1301
-20
lines changed

crud-operations/crud_fastapi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from crud_sql_alchemy import Bird, init_db
22
from crud_sql_alchemy import Session as SessionLocal
3-
from fastapi import Depends, FastAPI, HTTPException
43
from pydantic import BaseModel, ConfigDict
54
from sqlalchemy import select
65
from sqlalchemy.orm import Session
76

7+
from fastapi import Depends, FastAPI, HTTPException
8+
89
app = FastAPI()
910
init_db()
1011

fastapi-url-shortener/source_code_final/shortener_app/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import validators
2-
from fastapi import Depends, FastAPI, HTTPException, Request
3-
from fastapi.responses import RedirectResponse
42
from sqlalchemy.orm import Session
53
from starlette.datastructures import URL
64

5+
from fastapi import Depends, FastAPI, HTTPException, Request
6+
from fastapi.responses import RedirectResponse
7+
78
from . import crud, models, schemas
89
from .config import get_settings
910
from .database import SessionLocal, engine

fastapi-url-shortener/source_code_step_2/shortener_app/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import secrets
22

33
import validators
4+
from sqlalchemy.orm import Session
5+
46
from fastapi import Depends, FastAPI, HTTPException, Request
57
from fastapi.responses import RedirectResponse
6-
from sqlalchemy.orm import Session
78

89
from . import models, schemas
910
from .database import SessionLocal, engine

fastapi-url-shortener/source_code_step_3/shortener_app/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import validators
2+
from sqlalchemy.orm import Session
3+
24
from fastapi import Depends, FastAPI, HTTPException, Request
35
from fastapi.responses import RedirectResponse
4-
from sqlalchemy.orm import Session
56

67
from . import crud, models, schemas
78
from .database import SessionLocal, engine

fastapi/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Get Started With FastAPI
2+
3+
This repository contains code snippets discussed in the associated tutorial [Get Started With FastAPI](https://realpython.com/get-started-with-fastapi/).
4+
5+
## Installation
6+
7+
The recommended way to install FastAPI is with the [`[standard]`](https://github.com/fastapi/fastapi/blob/16d75d90eb96976a57b94cc24e4018859cd54c4d/pyproject.toml#L60) extra dependencies. This ensures you get all the tools you need for developing an API without having to hunt down additional packages later:
8+
9+
```console
10+
$ python -m pip install "fastapi[standard]"
11+
```
12+
13+
The quotes around `"fastapi[standard]"` ensure the command works correctly across different [terminals](https://realpython.com/terminal-commands/) and operating systems. With the command above, you install several useful packages, including the [FastAPI CLI](https://fastapi.tiangolo.com/fastapi-cli/) and [uvicorn](https://www.uvicorn.org/), an [ASGI](https://en.wikipedia.org/wiki/Asynchronous_Server_Gateway_Interface) server for running your application.
14+
15+
You can also use the `requirements.txt` file in this folder and run `python -m pip install -r requirements.txt` to install the standard dependencies of FastAPI.

fastapi/main.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from pydantic import BaseModel
2+
3+
from fastapi import FastAPI
4+
5+
app = FastAPI()
6+
7+
books = [
8+
{"id": 1, "title": "Python Basics", "author": "Real P.", "pages": 635},
9+
{
10+
"id": 2,
11+
"title": "Breaking the Rules",
12+
"author": "Stephen G.",
13+
"pages": 99,
14+
},
15+
]
16+
17+
18+
class Book(BaseModel):
19+
title: str
20+
author: str
21+
pages: int
22+
23+
24+
@app.get("/books")
25+
def get_books(limit: int | None = None):
26+
"""Get all books, optionally limited by count."""
27+
if limit:
28+
return {"books": books[:limit]}
29+
return {"books": books}
30+
31+
32+
@app.get("/books/{book_id}")
33+
def get_book(book_id: int):
34+
"""Get a specific book by ID."""
35+
for book in books:
36+
if book["id"] == book_id:
37+
return book
38+
return {"error": "Book not found"}
39+
40+
41+
@app.post("/books")
42+
def create_book(book: Book):
43+
"""Create a new book entry."""
44+
new_book = {
45+
"id": len(books) + 1,
46+
"title": book.title,
47+
"author": book.author,
48+
"pages": book.pages,
49+
}
50+
books.append(new_book)
51+
return new_book

fastapi/requirements.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
annotated-types==0.7.0
2+
anyio==4.10.0
3+
certifi==2025.8.3
4+
click==8.2.1
5+
dnspython==2.7.0
6+
email_validator==2.2.0
7+
fastapi==0.116.1
8+
fastapi-cli==0.0.8
9+
fastapi-cloud-cli==0.1.5
10+
h11==0.16.0
11+
httpcore==1.0.9
12+
httptools==0.6.4
13+
httpx==0.28.1
14+
idna==3.10
15+
Jinja2==3.1.6
16+
markdown-it-py==4.0.0
17+
MarkupSafe==3.0.2
18+
mdurl==0.1.2
19+
pydantic==2.11.7
20+
pydantic_core==2.33.2
21+
Pygments==2.19.2
22+
python-dotenv==1.1.1
23+
python-multipart==0.0.20
24+
PyYAML==6.0.2
25+
rich==14.1.0
26+
rich-toolkit==0.15.0
27+
rignore==0.6.4
28+
sentry-sdk==2.34.1
29+
shellingham==1.5.4
30+
sniffio==1.3.1
31+
starlette==0.47.2
32+
typer==0.16.0
33+
typing-inspection==0.4.1
34+
typing_extensions==4.14.1
35+
urllib3==2.5.0
36+
uvicorn==0.35.0
37+
uvloop==0.21.0
38+
watchfiles==1.1.0
39+
websockets==15.0.1

langchain-rag-app/source_code_final/chatbot_api/src/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from agents.hospital_rag_agent import hospital_rag_agent_executor
2-
from fastapi import FastAPI
32
from models.hospital_rag_query import HospitalQueryInput, HospitalQueryOutput
43
from utils.async_utils import async_retry
54

5+
from fastapi import FastAPI
6+
67
app = FastAPI(
78
title="Hospital Chatbot",
89
description="Endpoints for a hospital system graph RAG chatbot",

langchain-rag-app/source_code_step_5/chatbot_api/src/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from agents.hospital_rag_agent import hospital_rag_agent_executor
2-
from fastapi import FastAPI
32
from models.hospital_rag_query import HospitalQueryInput, HospitalQueryOutput
43
from utils.async_utils import async_retry
54

5+
from fastapi import FastAPI
6+
67
app = FastAPI(
78
title="Hospital Chatbot",
89
description="Endpoints for a hospital system graph RAG chatbot",

polars-vs-pandas/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Polars vs pandas: What's the Difference?
2+
3+
The materials contained in this folder are designed to complement the Real Python tutorial [Polars vs pandas: What's the Difference?](https://realpython.com/polars-vs-pandas/).
4+
5+
Your download bundle contains the following files:
6+
7+
| File | Description |
8+
|-----------------------------------------|------------------------------------------------------------------------------------------------------------|
9+
| `benchmark.py` | This script performs time tests for DataFrames and a LazyFrame. |
10+
| `conversions.py` | This file contains the code used to convert between pandas and Polars DataFrames, plus a Narwhals example. |
11+
| `data_generation.py` | This script contains the `generate_data()` function used to generate different quantities of data. |
12+
| `online_retail.parquet` | This Parquet file contains retail data used in some of the queries. |
13+
| `pandas_polars_demo.py` | This file contains the code used to illustrate the differences between pandas and Polars syntax. |
14+
| `plots.ipynb` | This Jupyter Notebook file contains the plotting code to demonstrate default plotting capabilities. |
15+
| `streaming_test.py` | This script performs time tests for a LazyFrame with streaming enabled. |

0 commit comments

Comments
 (0)