{"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.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install phrase-api"],"cli":null},"imports":["import phrase_api; config = phrase_api.Configuration()","import phrase_api; client = phrase_api.ApiClient(config)","import phrase_api; locales_api = phrase_api.LocalesApi(client)","from phrase_api.rest import ApiException"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}