This release is a pre-release and may not be stable for production use.
fastapi-locale
Internationalization for FastAPI, built on standard gettext catalogs.
Documentation: https://fastapi-locale.readthedocs.io
- Picks a locale for every request from a query parameter,
Accept-Languageor a cookie, 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: release candidate. Install it with
pip install --pre fastapi-locale. The engineering documents (requirements, models, architecture, decisions) are 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.0rc2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_locale-0.1.0rc2.tar.gz | 213.6 kB | With provenance | Details for fastapi_locale-0.1.0rc2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_locale-0.1.0rc2-py3-none-any.whl | Python 3 | none | any | Details for fastapi_locale-0.1.0rc2-py3-none-any.whl |
Total release size: 281.6 kB
Release files / fastapi_locale-0.1.0rc2.tar.gz
| Download URL | fastapi_locale-0.1.0rc2.tar.gz |
|---|---|
| Size | 213.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
250638ac152c7fbab0301419e5978f0adc64fa05d9d59305434f3d08a3fbc778
|
|
BLAKE2b-256 checksum How to use checksums |
65f23dea217491acaa0fd7dd9992781512b414b001b911e60313c261c20e427e
|
| 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 Oct 4, 2026.
Transparency logRelease files / fastapi_locale-0.1.0rc2-py3-none-any.whl
| Download URL | fastapi_locale-0.1.0rc2-py3-none-any.whl |
|---|---|
| Size | 68.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef9baa51b09210ddd2d075ef969f55fd3219c1cfa3d184b6b4ceb9a56d934bf3
|
|
BLAKE2b-256 checksum How to use checksums |
6bbcfac962627d95bf85fbe006c0030c4c996f4b9740a17ce64c6711cf912704
|
| 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 Oct 4, 2026.
Transparency logSecurity for fastapi-locale 0.1.0rc2
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for fastapi_locale-0.1.0rc2.tar.gz
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 Oct 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.