Skip to main content

High-performance i18n for FastAPI with Rust-powered translation engine

Project description

i18n-fastapi

PyPI version Python versions License CI

High-performance internationalization for FastAPI, powered by a Rust translation engine with automatic Python fallback.

Features

  • Rust-powered engine — blazing-fast translation lookups via PyO3, with pure Python fallback
  • ICU plural support — zero / one / two / few / many / other
  • Configurable locale detection — query params, cookies, headers, path prefix, in any priority order
  • Plugin pattern — one-line setup with I18n(app)
  • Multiple locale directories — shared + per-module translations with filename-based namespacing
  • Duplicate key detection — catch conflicts at startup, not at runtime
  • Hot reload — watch translation files during development
  • Built-in endpointGET /i18n/languages returns available locales
  • FastAPI dependencies — inject Locale and TranslateFunc into route handlers

Installation

pip install i18n-fastapi

For hot reload during development:

pip install "i18n-fastapi[reload]"

Quick Start

Create translation files:

locales/
├── en/
│   └── messages.json    # {"greeting": "Hello {name}"}
└── es/
    └── messages.json    # {"greeting": "Hola {name}"}

Set up your app:

from fastapi import FastAPI
from i18n_fastapi import I18n, t

app = FastAPI()
I18n(app)

@app.get("/greet")
async def greet():
    return {"message": t("messages.greeting", name="World")}

Request with ?lang=es or Accept-Language: es and the response adapts automatically.

Documentation

Author

Johnatan Palacios Londoño — johnatan.palacios@utp.edu.co

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

i18n_fastapi-0.1.0-cp311-cp311-win_amd64.whl (224.2 kB view details)

Uploaded CPython 3.11Windows x86-64

i18n_fastapi-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (321.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

i18n_fastapi-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (367.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file i18n_fastapi-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for i18n_fastapi-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b709c4d43945390d0e66ed155214f5ce5fe7886c78e0435b90eb6b1c00112b07
MD5 05e5ed17eb1d52a6c23422f11f3a0572
BLAKE2b-256 f762b0ee311622c2b53a606e39ebaf036f04d417ff6f659be60a780d0c2eed36

See more details on using hashes here.

Provenance

The following attestation bundles were made for i18n_fastapi-0.1.0-cp311-cp311-win_amd64.whl:

Publisher: release.yml on JohnatanPalacios/i18n-fastapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file i18n_fastapi-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for i18n_fastapi-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 71a59cc56f86a7b89ab670bc62adc306df1e6497d1e105ea7a8dbd7b7c3cfa8a
MD5 89e4c0ba39eb8c195e3ccde909f056ef
BLAKE2b-256 3f8e3044b49f5aa6e89ba8d86030d45ab19afaee0c636efdfe50955e946474bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for i18n_fastapi-0.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on JohnatanPalacios/i18n-fastapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file i18n_fastapi-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for i18n_fastapi-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 37b8923d177baea793556121e6745532076b66e1e863370a6820e6ca6d4e03d0
MD5 97bf9c6de185992bd68a7edcef308c19
BLAKE2b-256 81145538696a39e0eabea18c5149b259ec8203e2caa9c3ea916950332a1f663a

See more details on using hashes here.

Provenance

The following attestation bundles were made for i18n_fastapi-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on JohnatanPalacios/i18n-fastapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page