{"id":10035,"library":"phrase-api","title":"Phrase Strings API Python Client","description":"The `phrase-api` library provides a Python client for interacting with the Phrase Strings API. It allows programmatic access to translation, localization, and internationalization resources. As a generated client, it frequently updates (often monthly) to reflect the latest API specification, with version `3.19.0` being the current stable release.","status":"active","version":"3.19.0","language":"en","source_language":"en","source_url":"https://github.com/phrase/phrase-python","tags":["API client","i18n","localization","translation","openapi-generated"],"install":[{"cmd":"pip install phrase-api","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Used to set API keys and other client-wide settings.","symbol":"Configuration","correct":"import phrase_api; config = phrase_api.Configuration()"},{"note":"The core HTTP client that handles requests and responses.","symbol":"ApiClient","correct":"import phrase_api; client = phrase_api.ApiClient(config)"},{"note":"One of many API modules (e.g., ProjectsApi, KeysApi, etc.) available directly under the `phrase_api` package.","symbol":"LocalesApi","correct":"import phrase_api; locales_api = phrase_api.LocalesApi(client)"},{"note":"Specific exception type raised for API errors (e.g., 4xx, 5xx responses).","symbol":"ApiException","correct":"from phrase_api.rest import ApiException"}],"quickstart":{"code":"import os\nimport phrase_api\nfrom phrase_api.rest import ApiException\nfrom pprint import pprint\n\n# Configure API key authorization\nconfiguration = phrase_api.Configuration()\nconfiguration.api_key['api_token'] = os.environ.get('PHRASE_API_TOKEN', 'YOUR_PHRASE_API_TOKEN')\n# Optionally, uncomment for bearer token prefix:\n# configuration.api_key_prefix['api_token'] = 'Bearer'\n\n# Create an instance of the API client\napi_client = phrase_api.ApiClient(configuration)\n\n# Create an instance of a specific API (e.g., LocalesApi)\nlocales_api = phrase_api.LocalesApi(api_client)\n\ntry:\n    # List locales for a project\n    project_id = os.environ.get('PHRASE_PROJECT_ID', 'YOUR_PHRASE_PROJECT_ID') # Replace with your project ID\n    \n    # Optional: Two-Factor-Authentication token, if required for your account/action\n    x_phrase_app_otp = os.environ.get('PHRASE_OTP_TOKEN') \n    \n    # Fetching the first page of locales, 25 per page\n    api_response = locales_api.locales_list(\n        project_id,\n        page=1, \n        per_page=25, \n        x_phrase_app_otp=x_phrase_app_otp\n    )\n    \n    print(\"Successfully listed locales:\")\n    pprint(api_response)\n\nexcept ApiException as e:\n    print(f\"Exception when calling LocalesApi->locales_list: {e}\")\n    if e.status == 401:\n        print(\"Hint: Check your PHRASE_API_TOKEN and ensure it has necessary permissions.\")\n    elif e.status == 404:\n        print(\"Hint: Check your PHRASE_PROJECT_ID and ensure it exists and is accessible.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to configure the client with an API token, create an API instance, and fetch a list of locales for a given project. It uses environment variables for sensitive data like API tokens and project IDs."},"warnings":[{"fix":"Refer to the Phrase API changelog and the specific client version's release notes for migration guides. Always test new versions in a non-production environment before deployment.","message":"As a generated client, new versions of `phrase-api` may introduce breaking changes to reflect updates in the underlying Phrase Strings API. Method signatures, object structures, or enum values can change without backward compatibility.","severity":"breaking","affected_versions":"All major versions (e.g., v3.x.x to v4.x.x, or even minor versions reflecting significant API changes)."},{"fix":"Always check for `page` and `per_page` parameters in list methods. To retrieve all items, you must manually loop through pages until an empty list is returned or the number of items is less than `per_page`.","message":"List operations (e.g., `locales_list`, `keys_list`) often implement server-side pagination. The client does not automatically fetch all pages.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If you encounter 403 errors or specific messages about 2FA, ensure you are passing the `x_phrase_app_otp` parameter to the API method if your Phrase account requires it. The value is typically a temporary code generated by your 2FA app.","message":"Some API operations or accounts might require a Two-Factor-Authentication (2FA) token, passed via the `X-PhraseApp-OTP` header.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Verify that `PHRASE_API_TOKEN` (or `configuration.api_key['api_token']`) is set correctly with a valid API token from your Phrase Strings account. Ensure the token has the scopes required for the specific API calls you are making.","cause":"The provided API token is either missing, incorrect, or lacks the necessary permissions for the requested action.","error":"phrase_api.rest.ApiException: (401) Reason: Unauthorized"},{"fix":"Double-check the IDs you are passing to API methods (e.g., `project_id`, `locale_id`). Confirm that the resource actually exists and that your API token has read/write access to it within the Phrase Strings platform.","cause":"The resource you are trying to access (e.g., project ID, locale ID, key ID) does not exist or your token does not have access to it.","error":"phrase_api.rest.ApiException: (404) Reason: Not Found"},{"fix":"Consult the official Phrase Strings API documentation or the library's GitHub repository to find the correct class name and its placement within the `phrase_api` package. It's usually `phrase_api.<ApiClassName>Api` (e.g., `phrase_api.ProjectsApi`).","cause":"You are trying to import or access an API class that does not exist or has a different name in the current `phrase-api` version.","error":"AttributeError: module 'phrase_api' has no attribute 'SomeApiClass'"}]}