This release is a pre-release and may not be stable for production use.
fastapi-locale
Internationalization for FastAPI, built on standard gettext catalogs.
- Picks a locale for every request from a query parameter, cookie or
Accept-Language, with RFC 4647 matching and correctContent-LanguageandVaryheaders. - Returns FastAPI's 422 validation errors in the client's language, with correct plural forms.
- Lazy text that works in Pydantic models, response models and
HTTPException.detail. - Dependency injection first:
LocaleDepandTranslatorDep, replaceable in tests. - Lets a dependency switch to the signed-in user's saved language for the rest of the request.
- A command line tool to extract, update, compile and check catalogs in CI.
Status: in development, not yet released. The design is in docs/.
Quick start
from fastapi import FastAPI, HTTPException
from fastapi_locale import LocaleConfig, Localization, TranslatorDep, gettext_lazy
i18n = Localization(
LocaleConfig(default_locale="en", supported_locales=["en", "hi", "de"], catalog_dirs=["locales"])
)
app = FastAPI()
i18n.install(app)
NOT_FOUND = gettext_lazy("Item not found")
@app.get("/items/{item_id}")
def read_item(item_id: int, tr: TranslatorDep) -> dict[str, str]:
if item_id != 1:
raise HTTPException(status_code=404, detail=NOT_FOUND)
return {"name": tr.gettext("Sample item")}
A request with Accept-Language: de now gets German text, German validation errors and
Content-Language: de.
Translation workflow
fastapi-locale extract # scan the code, write locales/messages.pot
fastapi-locale init --locale hi # start a new language
fastapi-locale update # merge new messages into every .po file
fastapi-locale compile # build .mo files
fastapi-locale check # fail CI when catalogs are stale or broken
Contributing
See CONTRIBUTING.md. The engineering documents (requirements, models, architecture, decisions and test plan) are in docs/.
License
MIT
Metadata
Release files for fastapi-locale 0.1.0rc1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastapi_locale-0.1.0rc1.tar.gz | 187.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_locale-0.1.0rc1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 248.5 kB
Release files / fastapi_locale-0.1.0rc1.tar.gz
| Download URL | fastapi_locale-0.1.0rc1.tar.gz |
|---|---|
| Size | 187.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fda53f8908ee263e8329dc9cec5b865a854b560d3ba188822be659adc81938b0
|
|
BLAKE2b-256 checksum How to use checksums |
822df2b45558816cbc4def4b51c7b176701de0ca2f122b8958ae8da0fc2eb7f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.
Transparency logRelease files / fastapi_locale-0.1.0rc1-py3-none-any.whl
| Download URL | fastapi_locale-0.1.0rc1-py3-none-any.whl |
|---|---|
| Size | 60.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a5719f3c6904aba3b3f1f2884ca98d67f4c096d8dfba807f53ed87790844437
|
|
BLAKE2b-256 checksum How to use checksums |
1539b76e040ca8354169b83a34c209d2c98c50d180d4af2a74f0e3079ac5410d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.
Transparency log