Skip to main content

Python client library for Crowdin API v2

Project description

Crowdin Python client Tweet GitHub Repo stars

The Crowdin Python client is a lightweight interface to the Crowdin API. It provides common services for making API requests.

Crowdin API is a full-featured RESTful API that helps you to integrate localization into your development process. The endpoints that we use allow you to easily make calls to retrieve information and to execute actions needed.

Installation

pip install crowdin-api-client

Quick Start

Create and list projects

from crowdin_api import CrowdinClient

class FirstCrowdinClient(CrowdinClient):
    TOKEN = "__token__"
    PROJECT_ID = 1 # Optional, set project id for all API's
    ORGANIZATION = "organizationName" # Optional, for Crowdin Enterprise only
    TIMEOUT = 60  # Optional, sets http request timeout.
    RETRY_DELAY = 0.1  # Optional, sets the delay between failed requests 
    MAX_RETRIES = 5  # Optional, sets the number of retries
    HEADERS = {"Some-Header": ""}  # Optional, sets additional http request headers
    PAGE_SIZE = 25  # Optional, sets default page size
    EXTENDED_REQUEST_PARAMS = {"some-parameters": ""}  # Optional, sets additional parameters for request

client = FirstCrowdinClient()

# Create Project
project_response = client.projects.add_project(name="New project", sourceLanguageId="en")

# Get list of Projects
projects = client.projects.list_projects()

# Get list of Projects with offset and limit
projects = client.projects.list_projects(offset=10, limit=20)

# Get list of Projects by page
projects = client.projects.list_projects(page=2) # offset=25, limit=25

Alternatively, you can create an instance of the CrowdinClient class with params like this:

from crowdin_api import CrowdinClient

# use the lower-case version of any of the constants above,
# at least provide token
client = CrowdinClient(token='__token__')

# ... continue as above

Add a file

from crowdin_api import CrowdinClient

client = CrowdinClient(token='__token__')

file_name = '__path_to_the_file__'

storage = client.storages.add_storage(open(file_name, 'rb'))

my_file = client.source_files.add_file(__project_id__, storage['data']['id'], file_name)

print(my_file)

Fetch all records

It is possible to fetch all records from paginatable methods (where we have limit and offset in arguments).

from crowdin_api import CrowdinClient

client = CrowdinClient(token='__token__')

# get all projects
print(client.projects.with_fetch_all().list_projects())

# get projects but not more than 1000
print(client.projects.with_fetch_all(1000).list_projects())

Sorting

An optional orderBy parameter is used to apply sorting.

from crowdin_api import CrowdinClient
from crowdin_api.sorting import Sorting, SortingOrder, SortingRule
from crowdin_api.api_resources.projects.enums import ListProjectsOrderBy

client = CrowdinClient(token='__token__')

sorting = Sorting(
    [
        SortingRule(ListProjectsOrderBy.ID, SortingOrder.ASC),
        SortingRule(ListProjectsOrderBy.NAME),
        SortingRule(ListProjectsOrderBy.CREATED_AT, SortingOrder.DESC),
    ]
)

print(client.projects.list_projects(orderBy=sorting))

Enum SortingOrder is also optional (ascending order applied by default).

Extended request parameters

The EXTENDED_REQUEST_PARAMS parameter allows you to set additional parameters for requests. For example, you can configure proxies or certificates.

The Client uses the requests library to make HTTP requests. You can pass any parameters that requests supports:

def request(
    self,
    method,
    url,
    params=None,
    data=None,
    headers=None,
    cookies=None,
    files=None,
    auth=None,
    timeout=None,
    allow_redirects=True,
    proxies=None,
    hooks=None,
    stream=None,
    verify=None,
    cert=None,
    json=None,
):

For example, you can set a proxy:

from crowdin_api import CrowdinClient

http_proxy = "http://10.10.1.10:3128"
https_proxy = "https://10.10.1.11:1080"
ftp_proxy = "ftp://10.10.1.10:3128"

proxies = {
  "http": http_proxy,
  "https": https_proxy,
  "ftp": ftp_proxy
}

class FirstCrowdinClient(CrowdinClient):
    EXTENDED_REQUEST_PARAMS = {"proxies": proxies}

GraphQL API

This library also provides the possibility to use GraphQL API:

from crowdin_api import CrowdinClient

client = CrowdinClient(
    token='{token}',
    organization='{organization}'
)

query = """
query {
  viewer {
    id
    name
  }
}
"""

# Execute the GraphQL query
response = client.graphql(query=query)

Seeking Assistance

If you find any problems or would like to suggest a feature, please read the How can I contribute section in our contributing guidelines.

Contributing

If you would like to contribute please read the Contributing guidelines.

License

The Crowdin Python client is licensed under the MIT License.
See the LICENSE file distributed with this work for additional
information regarding copyright ownership.

Except as contained in the LICENSE file, the name(s) of the above copyright
holders shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written authorization.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crowdin_api_client-1.27.0.tar.gz (75.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crowdin_api_client-1.27.0-py3-none-any.whl (116.4 kB view details)

Uploaded Python 3

File details

Details for the file crowdin_api_client-1.27.0.tar.gz.

File metadata

  • Download URL: crowdin_api_client-1.27.0.tar.gz
  • Upload date:
  • Size: 75.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for crowdin_api_client-1.27.0.tar.gz
Algorithm Hash digest
SHA256 da0433b973460696990bc37c0b31971c6dee85c7150a4c031f6a58cc409af32c
MD5 8883a7e19e09552ba1f757e42655e8ac
BLAKE2b-256 de0a8b889372951f73249c036c800f16ebe5cffa8804559057a28d4bb97f2013

See more details on using hashes here.

File details

Details for the file crowdin_api_client-1.27.0-py3-none-any.whl.

File metadata

File hashes

Hashes for crowdin_api_client-1.27.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4dd2ec4b2909260721b93cfd29702e1d3e31e149c276d1cc95cf8044dec187b3
MD5 bccd97af32fd44012fc8166c0aa92797
BLAKE2b-256 ea5bd3f9928af678b35e0176ea853a11c617fb4ab314b80121f819911f11c270

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page