Skip to main content

gp-python-client

gp-python-client is the official Python client for IBM Globalization Pipeline.

IBM Globalization Pipeline is a DevOps integrated application translation management service that you can use to rapidly translate and release cloud and mobile applications to your global customers. Access IBM Globalization Pipeline capabilities through its dashboard, RESTful API, or integrate it seamlessly into your application's Delivery Pipeline.

This package expands on the gettext module (avaliable as part of the Python standard library) and provides functionality for Python applications to use the Globalization Pipeline service.

Getting started

To get started, you should familiarize yourself with the service itself. A good place to begin is by reading the Quick Start Guide and the official Getting Started with IBM Globalization documentation.

The documentation explains how to find the service on IBM Cloud; authentication mechanisms supported; create a new service instance; create a new bundle; access the translated messages.

Demo

This demo Bluemix app uses the Globalization Pipeline with the Python client to display a short welcome message that is translated in several languages. The source code for the demo app can be found in the demo dir.

Installation

To install gp-python-client, simply run:

$ pip install gp-python-client

Or if you're oldschool, run:

$ easy_install gp-python-client

API

The API documentation for the package can be found here. If the link is broken, you can generate the documentation yourself.

Examples

Example 1 - Bluemix app:

This sample code will allow you to get started using the Globalization Pipeline service in your Bluemix app. The example assumes the Bluemix app has been connected to a Globalization Pipeline service instance and has a bundle named myBundle, and that the bundle contains a source string with key greet.

>>> from gpclient import GPClient, GPServiceAccount, GPTranslations
>>> import locale
>>>
>>> acc = GPServiceAccount()
>>> client = GPClient(acc)
>>>
>>> languages=[locale.getdefaultlocale()[0]] # languages=['fr_CA']
>>>
>>> t = client.translation(bundleId='myBundle', languages=languages)
>>> _ = t.gettext # create alias for method
>>>
>>> print _('greet') # 'greet' key's French translated value will be used
Bonjour
>>>

Example 2 - Non-Bluemix app:

This sample code will allow you to get started using the Globalization Pipeline service in a standalone Python app that is not hosted on Bluemix. The example assumes a Globalization Pipeline service instance exists with a bundle named myBundle, and that the bundle contains a source string with key exit.

You will need the service instance credentials.

>>> from gpclient import GPClient, GPServiceAccount, GPTranslations
>>> import locale
>>>
>>> acc = GPServiceAccount(url=url, instanceId=instId,
    userId=userId, password=passwd) # Using Globalization Pipeline authentication
# Using IAM 
# acc = GPServiceAccount(url=url, instanceId=instanceId,
#                                apiKey=apiKey)
>>> client = GPClient(acc)
>>>
>>> languages=[locale.getdefaultlocale()[0]] # languages=['es-mx']
>>>
>>> t = client.translation(bundleId='myBundle', languages=languages)
>>> _ = t.gettext # create alias for method
>>>
>>> print _('exit') # 'exit' key's Spanish translated value will be used
Adiós
>>>

You can also provide the service credentials through a JSON file as shown in the snippet below

>>> from gpclient import GPClient, GPServiceAccount
>>>
>>> acc = GPServiceAccount(credentialsJson="./local_credentials.json")
>>> client = GPClient(acc)

Obtaining language/locale codes

This package requires that valid (BCP47 compliant) language/locale codes be provided when asked; for example, when calling GPClient.translation() (see Examples). From these codes, the language, region, and script subtags will be extracted.

Some example codes are:

  • zh-Hans
  • pt-BR
  • ja
  • en_US

There are several ways to get the code for the working locale. One way is to use the locale module (avaliable as part of the Python standard library).

>>> import locale
>>> myLocale = locale.getdefaultlocale()
>>> print myLocale
('en_US', 'UTF-8')
>>> code = myLocale[0]
>>> print code
en_US

For the above example, the language code is en_US - where en is the language subtag, and US is the region subtag.

Running Tests

Refer to test/README.md.

Generating documentation

Documentation can be generated using Sphinx.

You must first install it:

$ pip install sphinx

Then, to auto generate the documentation, run:

$ cd $BASEDIR/docs
$ make clean
$ make html

To navigate the documentation, open $BASEDIR/docs/_build/html/index.html.

Creating distribution package

First update CHANGES.txt and setup.py if necessary (e.g. update version number), then create the preferred distribution package.

Wheel distribution (Recommended)

$ pip install wheel
$ python setup.py bdist_wheel

Source distribution

$ python setup.py sdist

Note: Source distribution contains tests as well.

Build distribution

$ python setup.py bdist

The new distribution files should be located under $BASEDIR/dist/.

Community

Contributing

See CONTRIBUTING.md.

License

Apache 2.0. See LICENSE.txt.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Metadata

Release files for gp-python-client 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gp-python-client 1.1.2
File Size Uploaded Provenance
gp-python-client-1.1.2.tar.gz 35.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gp-python-client 1.1.2
File Interpreter ABI Platform
gp_python_client-1.1.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 55.1 kB

Release files / gp-python-client-1.1.2.tar.gz

Download URL gp-python-client-1.1.2.tar.gz
Size 35.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dbfea5d2b37afe784b34cdb3868899e98a81b70f27809ccf996b3c81f14baa26
BLAKE2b-256 checksum
How to use checksums
5a57d32c62c4a2311dac1b1d7ef2342275ab282d89d54a7fef4b7a5e6ef0283f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

Release files / gp_python_client-1.1.2-py2.py3-none-any.whl

Download URL gp_python_client-1.1.2-py2.py3-none-any.whl
Size 19.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f2a3185df672e097bc91d1cb12b2b0a0f8caed36791963d092ff1efe859d74d1
BLAKE2b-256 checksum
How to use checksums
b33602956110b0aa09e5b0e1084e6604aed43f83dd376ed5288f42b28f02cc16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

Security for gp-python-client 1.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page