{"id":10166,"library":"python-lokalise-api","title":"Lokalise API Client for Python","description":"The official Python interface for the Lokalise API v2, designed to interact with your Lokalise translation projects programmatically. It provides a comprehensive set of functionalities to manage projects, keys, translations, and more. Currently at version 4.0.4, the library maintains an active release cadence, frequently adding new features and ensuring compatibility with the latest Lokalise API changes.","status":"active","version":"4.0.4","language":"en","source_language":"en","source_url":"https://github.com/lokalise/python-lokalise-api","tags":["API client","localization","Lokalise","translation"],"install":[{"cmd":"pip install python-lokalise-api","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for making HTTP requests to the Lokalise API, replacing the 'requests' library in v4.x.","package":"httpx","optional":false},{"reason":"Used for data validation and parsing API responses into strongly-typed models (v2.x required for v4.x).","package":"pydantic","optional":false}],"imports":[{"note":"The client class is nested within the 'client' submodule since v4.x.","wrong":"from lokalise import LokaliseClient","symbol":"LokaliseClient","correct":"from lokalise.client import LokaliseClient"}],"quickstart":{"code":"import os\nfrom lokalise.client import LokaliseClient\n\n# Get your Lokalise API token from environment variables for security\nAPI_TOKEN = os.environ.get('LOKALISE_API_TOKEN', '')\n\nif not API_TOKEN:\n    print(\"Error: LOKALISE_API_TOKEN environment variable not set.\")\n    print(\"Please set it (e.g., export LOKALISE_API_TOKEN='YOUR_TOKEN') and retry.\")\nelse:\n    try:\n        client = LokaliseClient(API_TOKEN)\n        # List projects (auto_pagination is False by default, returns first page)\n        projects = client.projects().list()\n        if projects:\n            print(f\"Found {len(projects)} projects on the first page:\")\n            for project in projects:\n                print(f\"  ID: {project.project_id}, Name: {project.name}\")\n        else:\n            print(\"No projects found or API token is invalid.\")\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n","lang":"python","description":"Initializes the LokaliseClient using an API token from environment variables and fetches a list of projects. This demonstrates basic client setup and interaction, ensuring the API token is handled securely."},"warnings":[{"fix":"Update your code to expect Pydantic model objects (e.g., `project.name` instead of `project['name']`). Ensure `pydantic>=2.0` and `httpx` are installed. Refer to the official v4.0.0 migration guide.","message":"Version 4.x introduced significant breaking changes from v3.x. The most notable change is the adoption of `pydantic` v2 for API responses, meaning methods now return strongly-typed Pydantic models instead of raw dictionaries. Additionally, the underlying HTTP client switched from `requests` to `httpx`.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"To get all results, you can either enable auto-pagination when initializing the client (`LokaliseClient(token, enable_auto_pagination=True)`) or manually iterate through pages using the `next_page()` method on the response object.","message":"By default, API calls that return a list of items (e.g., `client.projects().list()`) will only return the first page of results. Automatic pagination is disabled by default for performance and control.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Store your API token in environment variables (e.g., `LOKALISE_API_TOKEN`) and access it using `os.environ.get('LOKALISE_API_TOKEN')`.","message":"API tokens should be handled securely. Hardcoding tokens directly into your script is a security risk, especially in production environments.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Access model fields directly as attributes: `project.name`, `project.project_id`, etc. (e.g., `print(project.name)`).","cause":"You are trying to access fields on a Pydantic model (introduced in v4.x) using dictionary-like syntax (e.g., `project.get('name')` or `project['name']`), which was common in v3.x.","error":"AttributeError: 'LokaliseProject' object has no attribute 'get'"},{"fix":"Update your import statement to `from lokalise.client import LokaliseClient`.","cause":"The main client class `LokaliseClient` is not directly under the top-level `lokalise` package in v4.x.","error":"ImportError: cannot import name 'LokaliseClient' from 'lokalise'"},{"fix":"Double-check your `LOKALISE_API_TOKEN` environment variable for correctness. Ensure it has the necessary read/write permissions for the resources you are trying to access in Lokalise.","cause":"The provided API token is invalid, expired, or does not have sufficient permissions for the requested operation.","error":"httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://api.lokalise.com/api/v2/projects'"}]}