Lokalise API Client for Python

4.0.4 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import os
from lokalise.client import LokaliseClient

# Get your Lokalise API token from environment variables for security
API_TOKEN = os.environ.get('LOKALISE_API_TOKEN', '')

if not API_TOKEN:
    print("Error: LOKALISE_API_TOKEN environment variable not set.")
    print("Please set it (e.g., export LOKALISE_API_TOKEN='YOUR_TOKEN') and retry.")
else:
    try:
        client = LokaliseClient(API_TOKEN)
        # List projects (auto_pagination is False by default, returns first page)
        projects = client.projects().list()
        if projects:
            print(f"Found {len(projects)} projects on the first page:")
            for project in projects:
                print(f"  ID: {project.project_id}, Name: {project.name}")
        else:
            print("No projects found or API token is invalid.")
    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →