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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ BCRYPT_ROUNDS=12
# Largest request body in bytes; larger requests get 413 before any route runs
MAX_REQUEST_BODY_BYTES=1048576

# --- Rate limits (per client IP, slowapi/limits syntax: 10/minute, 100/hour) ---
# --- Rate limits (per client IP, `limits` syntax: 10/minute, 100/hour) ---
RATE_LIMIT_LOGIN=60/minute
RATE_LIMIT_REGISTER=10/minute
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ docs/ # setup, authentication, api, schemas, releasing, known_issue
* **Dependencies**: `poetry add <pkg>` (dev tools: `--group dev`), then `poetry install`.
Ranges in `pyproject.toml` are open to the next major; `poetry.lock` is the pin.
Update with `poetry update` (or `poetry lock --regenerate` for every transitive
package) and run the suite. SQLAlchemy is held below 2.1 until it ships wheels.
package) and run the suite.
* **Test database**: `createdb basic_api_test_db` and the `DB_*` variables
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ notes (see [docs/releasing.md](docs/releasing.md)).
pycparser from the dependency tree; HS256 needs none of them (#9).

### Dependencies
- SQLAlchemy 2.0.54 to 2.1.4, declared as `sqlalchemy[asyncio]` because 2.1
installs greenlet, which the asyncio extension needs, only through that
extra. 2.1 ships a Python 3.15 wheel, so the Cython speedups are back on
3.15. Of the 2.1 behaviour changes, none reaches this code: the database
URL names `asyncpg` explicitly (2.1 defaults `postgresql://` to psycopg 3),
there are no PostgreSQL named types, and autoflush now also runs before
Core statements such as the health check's `SELECT 1`, which never has
pending changes. The suite passes with every SQLAlchemy warning as an error.
SQLModel 0.0.48 added 2.1 support (#21).
- Refresh before the move to Python 3.15: pydantic 2.13.5 to 2.14.1 with
pydantic-core 2.50.1, the first release with Python 3.15 wheels; FastAPI
0.142.2 to 0.143.1; Starlette 1.7.0 to 1.8.0; Black 26.10.0 to 26.10.1 and
Expand Down Expand Up @@ -71,6 +80,15 @@ notes (see [docs/releasing.md](docs/releasing.md)).
`RequestBodyLimitMiddleware` answers 413 before any route runs (#13).

### Changed
- The rate limiter is built directly on `limits` (fixed window, in-process
memory) instead of slowapi, whose `asyncio.iscoroutinefunction` call is
removed in Python 3.16 and unfixed upstream. A limited route now declares
`Depends(limiter.limit(...))` instead of a decorator plus `request` and
`response` parameters it never used. Same limits, same per-IP and per-route
counting, same `429` body and `Retry-After`; the `429` now also carries the
`X-RateLimit` headers, and `X-RateLimit-Reset` is a whole number of seconds.
The `pytest.ini` warning filter for slowapi is gone, so the suite runs with
no filtered warnings (#22).
- Python 3.15: `.python-version` says `3.15`, `requires-python` is
`>=3.15,<4.0`, Black targets `py315`, mypy checks against 3.15 and the GitLab
pipeline runs on `python:3.15-slim`. Every dependency ships a 3.15 wheel or is
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ configuration right. That work is done here, tested, and documented.
time and return the same body
- Passwords hashed with bcrypt over a SHA-256 pre-hash, off the event loop
- Client API key as a declared OpenAPI security scheme on every `/api` route
- Rate limits per client IP on login and registration (slowapi)
- Rate limits per client IP on login and registration (`limits`)
- User self-service: read, update, change password and delete the own account
- Async PostgreSQL through SQLModel and asyncpg; health check that pings it
- One `config.py` reads and validates every environment variable at startup
Expand Down
3 changes: 2 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ same id; quote it when reporting a problem.

**Rate limits**: `POST /token` and `POST /api/users/` answer with
`X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset` (Unix
time at which the window resets); over the limit, a `429` with `Retry-After`.
time at which the window resets); over the limit, a `429` with `Retry-After`
and the same three headers with nothing remaining.

**Auth** column: `key` is the `X-API-Key` header, `token` is
`Authorization: Bearer <jwt>`. See [Authentication](authentication.md) for the
Expand Down
39 changes: 2 additions & 37 deletions docs/known_issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ looks like. Remove an entry in the same change that fixes it.
| Code | [Startup validation and the login limit are untested](#startup-validation-and-the-login-limit-are-untested) | Low |
| Code | [Application code detects the test runner](#application-code-detects-the-test-runner) | Low |
| Code | [The root banner reports healthy without checking](#the-root-banner-reports-healthy-without-checking) | Low |
| Dependencies | [slowapi calls an asyncio API removed in Python 3.16](#slowapi-calls-an-asyncio-api-removed-in-python-316) | Low |

---

Expand Down Expand Up @@ -152,8 +151,8 @@ effective limit; a restart resets it. Behind a reverse proxy on another host,
uvicorn must be told to trust its forwarded headers (`--forwarded-allow-ips`),
or every client shares one bucket.

**Fix:** shared storage for the counts (slowapi supports Redis) when running
more than one worker.
**Fix:** shared storage for the counts (`limits` has Redis, Memcached and
MongoDB storages) when running more than one worker.

### No metrics, tracing or error tracking

Expand Down Expand Up @@ -247,37 +246,3 @@ healthy service with its database down.

**Fix:** drop the `status` field from the banner, or have it call the same
`ping()` as `/health`.

---

## Dependencies

### SQLAlchemy 2.0 runs without its C extensions on Python 3.15

**Where:** `pyproject.toml` (`sqlalchemy (>=2.0.54,<2.1)`).

SQLAlchemy 2.0.x publishes compiled wheels up to Python 3.14 only, so on 3.15
pip installs the pure Python wheel and the Cython speedups (row processing,
result collections) are replaced by their Python implementations. Everything
works and the suite passes; result processing is slower than on 3.14 with the
compiled wheel. SQLAlchemy 2.1.x ships Python 3.15 wheels.

**Fix:** move to SQLAlchemy 2.1 (a new minor with behaviour changes, read its
migration notes first; SQLModel 0.0.48 allows `<2.2`) and drop the `<2.1`
constraint in `pyproject.toml`.

### slowapi calls an asyncio API removed in Python 3.16

**Where:** `slowapi/extension.py` (version 0.1.10), surfaced by `pytest.ini`.

On Python 3.14 and 3.15 the test run reports `DeprecationWarning: 'asyncio.iscoroutinefunction'
is deprecated and slated for removal in Python 3.16; use
inspect.iscoroutinefunction()`, raised from slowapi when it wraps a rate-limited
route. Nothing is wrong today; on Python 3.16 the rate limiter would stop
working unless slowapi releases a fix. `pytest.ini` filters this one warning
for the `slowapi` module only, so the summary stays readable; the filter must go
when slowapi fixes it or when this project replaces slowapi.

**Fix:** upgrade slowapi once a release uses `inspect.iscoroutinefunction`, then
remove the filter; if none appears before 3.16 matters, replace slowapi (the
limiter lives in one module, `limiter.py`).
Loading
Loading