Git Product home page Git Product logo

python-lokalise-api's Introduction

Lokalise API v2 official Python interface

PyPI CI Coverage Status Downloads Docs

Official Python 3 interface for the Lokalise APIv2 that represents returned data as Python objects.

Quick start

This plugin requires Python 3.8 and above. Install it:

pip install python-lokalise-api

Obtain a Lokalise API token (in your Personal profile) and use it:

import lokalise
client = lokalise.Client('YOUR_API_TOKEN')
project = client.project('123.abc')
print(project.name)

client.upload_file(project.project_id, {
    "data": 'ZnI6DQogIHRlc3Q6IHRyYW5zbGF0aW9u',
    "filename": 'python_upload.yml',
    "lang_iso": 'en'
})

translation_keys = client.keys(project.project_id, {"page": 2,
    "limit": 3,
    "disable_references": "1"})
translation_keys.items[0].key_name['web'] # => "sign_up"

You can also use OAuth 2 tokens:

client = lokalise.OAuthClient('YOUR_OAUTH2_API_TOKEN')

project = client.project('123.abc')

Documentation

Find detailed documentation at python-lokalise-api.readthedocs.io.

License

This plugin is licensed under the BSD 3 Clause License.

Copyright (c) Lokalise group and Ilya Krukowski

python-lokalise-api's People

Contributors

beinarovic avatar bodrovis avatar carlmanaster avatar dependabot[bot] avatar mvasquezdxc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

python-lokalise-api's Issues

Any plan for asyncio support ?

The feature I'd like is an asyncio version of the Lokalize client.

Additional context
When using asyncio in a python project is better to go full async vs mixing sync / async.

Thanks !

Unclear on initial setup for python to push keys to project

I've been following the docs but am still unsure on how to set up my project to push keys to my project from a python file.
Below is what I have for a short test:
``
import lokalise
client = lokalise.Client('token')
project = client.project('LokaliseTestTwo')
print(project.name)

client.create_keys('2865291361eb7dbb69b3d5.79158357', [
{
"key_name": "python_1",
"platforms": ["ios", "android"],
"description": "Created by Python",
"translations": [
{
"language_iso": "en",
"translation": "Hi from Python"
}
]
},
{
"key_name": "python_2",
"platforms": ["web"],
"translations": [
{
"language_iso": "en",
"translation": "Hi from Python"
}
]
}
])
``

However, I am getting the error:

raise errors.ERROR_CODES[code](msg, code) lokalise.errors.BadRequest: ('Invalid `project_id` parameter', 400) PS C:\Users\spira\OneDrive\Documents\PersonalProjects\lokaliseProjectTwo>

The docs suggest the following to instantiate a connection:
project = client.project('123.abc') project.name # => "Sample Project" project.description # => "This is a demo project."
My question is does the line
project = client.project('123.abc')

take the name of the project as a string as a parameter or something else? Would love to be able to work through this. Given the popularity of Python, maybe this is something you could consider for a tutorial?
Best,
Trevor

How could I retrieve the pull request details

The feature I'd like is to retrieve the pull request details of a feature branch

Additional context
Hi mate. Is there any support for getting the pull requests details in the documentation? I could not find any of it. It would be better if I could get the pull request URL. Thank you.

Invalid type hints for `params` in `create_webhook` and `update_webhook`

Describe the bug

It is defined in

def create_webhook(self, project_id: str,
params: Dict[str, str]
) -> WebhookModel:
and
def update_webhook(self, project_id: str, webhook_id: str,
params: Optional[Dict[str, str]] = None) -> WebhookModel:

as [Dict[str, str]], but one of possible params (and required in the case of create_webhook) is events, which according to the docs should be an array of strings:
https://developers.lokalise.com/reference/create-a-webhook
https://python-lokalise-api.readthedocs.io/en/v2.1.1/api/webhooks.html#create-webhook

This causes a false positive in type checkers, e.g. in PyCharm:
2023-08-08_16-29-33_CEST_screenshot

To Reproduce

  1. Call create_webhook and update_webhook with parameter events.
  2. Run a type checker on the code (e.g. PyCharm's built-in one or mypy, or others).

Expected behavior
No error from a type checker.

Your environment:
n/a

Additional context
n/a

Cannot get project info for branch

In the documentation, it looks like you can access branch info like this :

If you are using project branching feature in Lokalise, simply add branch name separated by semicolon to the project ID in any endpoint to access the branch, i.e. 3002780358964f9bab5a92.87762498:feature/new-release.

When I try to do this, I get an invalid project id parameter.

Is there a way to get statistics for a branch of a project language?

CloudQuery Source Plugin?

Hi Team, hopefully this is right place to ask, if not, I'd appreciate if you can direct me.

I'm the founder of cloudquery.io, a high performance open source ELT framework.

Our users are interested in a Lokalise CloudQuery plugin, but as we cannot maintain all the plugins ourselves, I was curious if this would be an interesting collaboration, where we would help implement an initial source plugin, and you will help maintain it.

This will give your users the ability to sync Lokalise data to any of their datalakes/data-warehouses/databases easily using any of the growing list of CQ destination plugins.

Best,
Yevgeny

Catalan lang_iso is not recognized by API

Describe the bug
I use the python-lokalise-api to upload my app's translations files. I works fine for most of the languages, but when it comes to catalan, it fails with the following error :

 File "/usr/local/lib/python3.9/site-packages/lokalise/client.py", line 375, in upload_file
    raw_process = self.get_endpoint("files"). \
  File "/usr/local/lib/python3.9/site-packages/lokalise/endpoints/files_endpoint.py", line 26, in upload
    return request.post(self.client, path + '/upload', params)
  File "/usr/local/lib/python3.9/site-packages/lokalise/request.py", line 53, in post
    return respond_with(requests.post(__prepare(BASE_URL + path),
  File "/usr/local/lib/python3.9/site-packages/lokalise/request.py", line 114, in respond_with
    respond_with_error(data, response.status_code)
  File "/usr/local/lib/python3.9/site-packages/lokalise/request.py", line 129, in respond_with_error
    raise errors.ERROR_CODES[code](msg, code)
lokalise.errors.BadRequest: ('Unknown `lang_iso`', 400)

To Reproduce
here is the code I use :

    file_content = io.open(my_file_path, mode="r", encoding="utf-8").read()
    base64_encoded_file_content_as_bytes = base64.b64encode(file_content.encode('utf-8'))
    base64_encoded_file_content = base64_encoded_file_content_as_bytes.decode('ascii')

    language = 'ca'
    client.upload_file(project.project_id, {
        "data": base64_encoded_file_content,
        "filename": my_file_path,
        "lang_iso": language
    })

For what it's worth, I also tried with language = 'cat' and the result is the same.

Expected behavior
I expect to be able to upload a catalan translation file without error.

Your environment:
-> docker (python:3.9.1-buster)
pip install python-lokalise-api

Additional context
Don't hesitate to ask if you think I forgot something important.

File Object (FileModel) doesn't return file_id

Describe the bug
FileModel doesn't return file_id

To Reproduce
files = client.files(project.project_id)

Expected behavior
FileModel to contain files.items which contains filename, key_count along with file_id

Your environment:
Unix + Python

Additional context

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.