Skip to content

Sync fastapi-url-shortener with the updated tutorial - #926

Open
realpython-bot wants to merge 1 commit into
masterfrom
maintenance/build-a-python-url-shortener-with-fastapi-20261027
Open

realpython-bot wants to merge 1 commit into
masterfrom
maintenance/build-a-python-url-shortener-with-fastapi-20261027

Conversation

@realpython-bot

Copy link
Copy Markdown
Collaborator

Syncs fastapi-url-shortener with the maintenance update of the tutorial Build a URL Shortener With FastAPI and Python.

What changed

In every step folder (source_code_step_1 to source_code_step_3, plus source_code_final):

  • Pydantic v2: config.py imports BaseSettings and SettingsConfigDict from the new pydantic-settings package and uses model_config = SettingsConfigDict(env_file=".env") in place of the inner class Config. schemas.py uses model_config = ConfigDict(from_attributes=True) in place of orm_mode = True.
  • SQLAlchemy 2.x: database.py imports declarative_base from sqlalchemy.orm in place of the deprecated sqlalchemy.ext.declarative.
  • requirements.txt: re-pinned to the article's new versions (fastapi 0.162.0, uvicorn 0.54.0, sqlalchemy 2.1.6, pydantic-settings 2.16.1, python-dotenv 1.2.4, validators 0.36.0), frozen with their transitive dependencies.

Before this change, the code doesn't run on any current FastAPI release, because from pydantic import BaseSettings raises PydanticImportError on Pydantic v2.

Verification

  • Fresh venv on Python 3.15.1 with the new requirements.txt. Each step folder was smoke-tested with TestClient and warnings turned into errors: settings load from .env. Step 2 creates a URL and rejects an invalid one (400). Step 3 also forwards (307). Final also checks the admin info (click count 1, admin_url under /admin/), deletes the URL, and gets a 404 afterward.
  • source_code_final also passes on Python 3.11.17, the new minimum version.
  • ruff@0.14.1 format --check and ruff@0.14.1 check pass.

Links

🤖 Generated with Claude Code

… Shortener With FastAPI and Python

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant