# python: Python 快速入门 URL: https://generaltranslation.com/zh/docs/python.mdx --- title: Python 快速入门 description: 在 10 分钟内为你的 Python 服务器添加多语言支持 --- 阅读完本指南后,你的 Python 服务器将能够根据请求的语言返回翻译后的内容。 General Translation 同时支持 **FastAPI** 和 **Flask**。请选择与你所用框架对应的指南: *** ## 概述 Python SDK 提供: * **`t()` function** — 内联翻译任意字符串,并支持变量插值 * **`derive()` function** — 根据源内容生成翻译后的值 * **自动检测区域设置** — 开箱即用,可解析 `Accept-Language` 标头 * **支持 `gt.config.json`** — 与所有 GT 库共用同一份配置文件 ## 快速示例 首先,在项目 root 中创建一个 `gt.config.json`: ```json title="gt.config.json" { "projectId": "your-project-id", "defaultLocale": "en", "locales": ["es", "fr"] } ``` 接下来,设置你的应用: ```python title="app.py" from fastapi import FastAPI from gt_fastapi import initialize_gt, t app = FastAPI() initialize_gt(app) @app.get("/") def index(): return {"message": t("Hello, world!")} ``` 然后翻译并发布你的内容: ```bash pip install gtx-cli gt translate --publish ``` 就是这样——现在,你的端点会根据请求的区域设置返回相应的翻译后的内容。 ## 后续步骤 * [FastAPI 快速入门](/docs/python/tutorials/fastapi-quickstart) — FastAPI 完整设置指南 * [Flask 快速入门](/docs/python/tutorials/flask-quickstart) — Flask 完整设置指南 * [`t()` API 参考](/docs/python/api/t) — 变量插值和相关选项 * [`initialize_gt()` API 参考](/docs/python/api/initialize-gt) — 全部配置选项