Smartling API SDK for Python
The Smartling API SDK for Python simplifies interaction with Smartling's cloud-based translation services APIs from Python applications. It provides a convenient, idiomatic Python interface to automate translation workflows, including file uploads, downloads, job management, and string operations. The current version is 3.1.9, and the library receives regular updates to support new API features and improvements.
Warnings
- breaking Smartling API breaking changes are released in new API versions. These can include removing/renaming endpoints or parameters, changing data types, making optional parameters required, or altering authentication requirements. Always refer to the official API reference for the specific version you are using.
- gotcha While Smartling's underlying API uses OAuth2 with expiring access tokens, the Python SDK automatically handles authentication and token refreshing. You provide your `userIdentifier` and `userSecret` once during client initialization, and the SDK manages the access token lifecycle.
- gotcha When importing translations for files that use HTML processing, a specific sequence of operations is required to prevent string fragmentation and loss of keys. Upload the file without HTML processing, import translations, then re-upload with HTML processing enabled.
- gotcha Importing Translation Memory eXchange (TMX) files into Smartling does not preserve plural information. Once imported, all plural form details for those translations are lost.
Install
-
pip install SmartlingApiSDK
Imports
- FilesApi
from smartlingApiSdk.api import FilesApi
- JobsApi
from smartlingApiSdk.api import JobsApi
- StringsApi
from smartlingApiSdk.api import StringsApi
- AccountProjectsApi
from smartlingApiSdk.api import AccountProjectsApi
- ContextApi
from smartlingApiSdk.api import ContextApi
- EstimatesApi
from smartlingApiSdk.api import EstimatesApi
- JobBatchesV2Api
from smartlingApiSdk.api import JobBatchesV2Api
- TagsApi
from smartlingApiSdk.api import TagsApi
- Credentials
from smartlingApiSdk.Credentials import Credentials
Quickstart
import os
from smartlingApiSdk.api import ProjectsApi
USER_IDENTIFIER = os.environ.get('SMARTLING_USER_IDENTIFIER', '')
USER_SECRET = os.environ.get('SMARTLING_USER_SECRET', '')
ACCOUNT_ID = os.environ.get('SMARTLING_ACCOUNT_ID', '')
if not all([USER_IDENTIFIER, USER_SECRET, ACCOUNT_ID]):
print("Please set SMARTLING_USER_IDENTIFIER, SMARTLING_USER_SECRET, and SMARTLING_ACCOUNT_ID environment variables.")
else:
try:
projects_api = ProjectsApi(USER_IDENTIFIER, USER_SECRET, ACCOUNT_ID)
# List projects in the account
projects_response = projects_api.listProjects()
print("Successfully connected to Smartling and listed projects.")
print(f"First 3 projects: {projects_response.data.items[:3]}")
except Exception as e:
print(f"An error occurred: {e}")