Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .github/dependabot.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
],
"labels": [
"dependencies"
],
"gitIgnoredAuthors": [
"66853113+pre-commit-ci[bot]@users.noreply.github.com"
],
"enabled": true,
"enabledManagers": [
"pep621",
"github-actions"
],
"ignoreDeps": []
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,5 @@ cython_debug/
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
test.db
.python-version
.changelog_generator.toml
.envrc
79 changes: 31 additions & 48 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ci:
autofix_commit_msg: "[pre-commit.ci] auto fixes from pre-commit.com hooks [dependabot skip]"
autofix_commit_msg: "[pre-commit.ci] auto fixes from pre-commit.com hooks"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: check-yaml
args: [--unsafe]
Expand All @@ -11,67 +11,50 @@ repos:
- id: check-merge-conflict
- id: end-of-file-fixer

# - repo: https://github.com/renovatebot/pre-commit-hooks
# rev: 39.69.2
# hooks:
# - id: renovate-config-validator
# files: ^renovate\.json$

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
rev: v0.11.2
hooks:
- id: ruff
args: ["--output-format=concise"]
name: "lint with ruff"
- id: ruff-format
name: "format with ruff"

- repo: https://github.com/jackdewinter/pymarkdown
rev: 0.9.16
hooks:
- id: pymarkdown
name: "check markdown"
exclude: ^.github/|CHANGELOG
args: [-d, "MD046", scan]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.8.0" # Use the sha / tag you want to point at
rev: "v1.15.0" # Use the sha / tag you want to point at
hooks:
- id: mypy
name: "Check with Mypy"

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.349
hooks:
- id: pyright
name: "Check with Pyright"
exclude: tests
additional_dependencies: [sqlalchemy, uvicorn, fastapi]

- repo: https://github.com/python-poetry/poetry
rev: "1.7.0"
hooks:
- id: poetry-check
name: "check poetry files"
# - id: poetry-lock
name: "run mypy"
additional_dependencies:
- pydantic
- sqladmin

- repo: https://github.com/python-poetry/poetry-plugin-export
rev: "1.6.0"
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.6.9
hooks:
- id: poetry-export
name: "export production dependencies"
# Update the uv lockfile
- id: uv-lock
- id: uv-export
name: "Export dependencies to 'requirements.txt'"
args:
[
"--without-hashes",
"-f",
"requirements.txt",
"-o",
"requirements.txt",
"--without",
"dev",
"--no-hashes",
"--no-dev",
"--no-emit-project",
"--output-file=requirements.txt",
]
- id: poetry-export
name: "export development dependencies"
- id: uv-export
name: "Export dev dependencies to 'requirements-dev.txt'"
args:
[
"--without-hashes",
"-f",
"requirements.txt",
"-o",
"requirements-dev.txt",
"--with",
"dev",
"--no-hashes",
"--no-emit-project",
"--output-file=requirements-dev.txt",
]
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023-2024 Grant Ramsay
Copyright (c) 2023-2025 Grant Ramsay

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ SQLAlchemy 2.0.
## Installation

Clone the repository and install the dependencies. This project uses
[Poetry](https://python-poetry.org/) for dependency management which should be
[uv](https://docs.astral.sh/uv/) for dependency management which should be
installed on your system first.

Install the project dependencies:

```console
poetry install
uv sync
```

Then switch to the virtual environment:

```console
poetry shell
source .venv/bin/activate
```

## Usage
Expand Down Expand Up @@ -109,7 +111,7 @@ This project is licensed under the terms of the MIT license.
```pre
MIT License

Copyright (c) 2023-2024 Grant Ramsay
Copyright (c) 2023-2025 Grant Ramsay

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Set up the database connection and session.""" ""

from collections.abc import AsyncGenerator
from typing import Any

Expand Down
9 changes: 6 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""An example of using FastAPI with Async SQLAlchemy 2."""

from collections.abc import AsyncGenerator, Sequence
from contextlib import asynccontextmanager
from typing import Any
from typing import Annotated, Any

import uvicorn
from db import get_db, init_models
Expand Down Expand Up @@ -30,7 +31,7 @@ async def root() -> dict[str, str]:

@app.post("/users/", response_model=UserResponseModel)
async def create_user(
name: str, email: str, session: AsyncSession = Depends(get_db)
name: str, email: str, session: Annotated[AsyncSession, Depends(get_db)]
) -> User:
"""Add a user."""
user = User(name=name, email=email)
Expand All @@ -39,7 +40,9 @@ async def create_user(


@app.get("/users/", response_model=Sequence[UserResponseModel])
async def get_users(session: AsyncSession = Depends(get_db)) -> Sequence[User]:
async def get_users(
session: Annotated[AsyncSession, Depends(get_db)],
) -> Sequence[User]:
"""Get all users."""
result = await session.execute(select(User))
return result.scalars().all()
Expand Down
1 change: 1 addition & 0 deletions models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Define Models used in this example."""

from db import Base
from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column
Expand Down
Loading