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.
from crowdin_api import CrowdinClient
classFirstCrowdinClient(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
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 projectsprint(client.projects.with_fetch_all().list_projects())
# get projects but not more than 1000print(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:
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.
FAQs
Python client library for Crowdin API v2
We found that crowdin-api-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.