# General Translation Python SDKs: Configuring General Translation
URL: https://generaltranslation.com/en-US/docs/python/guides/configuring.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: How to initialize General Translation in Python with your app, locales, and translation delivery in Flask, FastAPI, or the core library.

The Python SDK is configured through a single call. In Flask and FastAPI this is `initialize_gt(app)`; in the core `gt-i18n` library you build an [`I18nManager`](/docs/python/reference/classes/i18n-manager) yourself. This guide covers both paths, plus how translations are delivered and preloaded.

## Configure a Flask or FastAPI app [#framework]

Call `initialize_gt(app)` once, before handling requests. It reads `gt.config.json`, creates the translation manager, registers per-request locale detection, and eager-loads translations.

<Tabs items={['Flask', 'FastAPI']}>
  <Tab value="Flask">
    ```python title="app.py"
    from flask import Flask
    from gt_flask import initialize_gt

    app = Flask(__name__)
    initialize_gt(app, default_locale="en", locales=["es", "fr"])
    ```
  </Tab>

  <Tab value="FastAPI">
    ```python title="main.py"
    from fastapi import FastAPI
    from gt_fastapi import initialize_gt

    app = FastAPI()
    initialize_gt(app, default_locale="en", locales=["es", "fr"])
    ```
  </Tab>
</Tabs>

Keyword arguments override `gt.config.json`. See the [configuration reference](/docs/python/reference/config) for every option and config key.

The two integrations share the same [`initialize_gt`](/docs/python/reference/functions/initialize-gt) signature; only their internals differ. Flask registers a `before_request` hook that sets the locale; FastAPI wraps the app lifespan (for eager loading) and adds an HTTP middleware that sets the locale.

## Configure the core library [#core]

The core `gt-i18n` package has no [`initialize_gt`](/docs/python/reference/functions/initialize-gt). Construct an [`I18nManager`](/docs/python/reference/classes/i18n-manager), register it as the active manager with [`set_i18n_manager`](/docs/python/reference/functions/set-i18n-manager), and set the request locale yourself. Locale detection and eager loading are not automatic here.

```python
from gt_i18n import I18nManager, set_i18n_manager, t

manager = I18nManager(default_locale="en", locales=["es", "fr"])
set_i18n_manager(manager)

manager.set_locale("es")   # you control locale per request
print(t("Hello, world!"))
```

Any translation function ([`t`](/docs/python/reference/functions/t), [`get_locale`](/docs/python/reference/functions/get-locale), and so on) reads from the manager set with [`set_i18n_manager`](/docs/python/reference/functions/set-i18n-manager). Calling one before a manager is set raises `RuntimeError`.

## Choose how translations are delivered [#delivery]

The SDK resolves translations in one of these modes:

- **General Translation CDN:** set `project_id` (in config or as a keyword argument) so translations load from the CDN at `{cache_url}/{project_id}/{locale}`. Override the base URL with `cache_url`.
- **Local files:** pass a `load_translations` callback that returns a `dict[str, str]` for a locale. This overrides the CDN loader. See [Storing translations locally](/docs/python/guides/storing-translations).

There is no API key. CDN delivery is driven entirely by `project_id` and `cache_url`.

## Preload translations [#preload]

The [`t`](/docs/python/reference/functions/t) function reads from an in-memory cache, so translations must be loaded before a request uses them. By default [`initialize_gt`](/docs/python/reference/functions/initialize-gt) eager-loads them at startup (`eager_loading=True`).

*Note: Eager loading runs only when target `locales` are known. On Flask this checks the `locales` you pass to [`initialize_gt`](/docs/python/reference/functions/initialize-gt) directly, not those loaded from `gt.config.json` — if your locales come only from the config file, pass them explicitly or load translations yourself. If translations are not yet loaded, [`t`](/docs/python/reference/functions/t) returns the source string.*

*Note: The in-memory cache expires after `cache_expiry_time` (default 60 seconds), and the synchronous read path that [`t`](/docs/python/reference/functions/t) uses does not reload it — after expiry [`t`](/docs/python/reference/functions/t) falls back to source strings until the async loader runs again. [`initialize_gt`](/docs/python/reference/functions/initialize-gt) does not expose `cache_expiry_time`.*

## Handle missing translations [#missing]

When a translation is missing, [`t`](/docs/python/reference/functions/t) returns the source string interpolated with your variables rather than raising, so a request always renders. Generate translations with the [CLI](/docs/cli/quickstart) before deploying so production has them ready.

## Next steps

- /docs/python/guides/translating-strings
- /docs/python/guides/detecting-locale
- /docs/python/guides/declaring-variables
- /docs/python/guides/storing-translations

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
