Skip to main content

Transifex Python Library

This library is a wrapper around the Transifex API, built to provide a simpler interface to users of the API.

At this moment, it supports only a subset of the endpoints of the API. In particular, it allows certain operations on Projects, Resources and Translations.

Usage

Initialization

Before making any requests, you need to setup the HTTP handler, which will be used for all subsequent requests.

Authentication works both with username/password or with an API token.

from txlib_too.http.auth import BasicAuth
from txlib_too.http.http_requests import HttpRequest
from txlib_too.registry import registry

credentials = BasicAuth(username='api', password='')

host = 'https:/www.transifex.com/'
conn = HttpRequest(host, auth=credentials)
registry.setup({'http_handler': conn})

Projects

TODO

Resources

Get resource

from txlib_too.api.resources import Resource
from txlib_too.http.exceptions import NotFoundError, ServerError

try:
    r = Resource.get(project_slug='project_slug', slug='resource_slug')
    print(r.slug) # 'resource_slug'
except NotFoundError:
    print('Resource not found')
except ServerError as e:
    print('Exception while retrieving resource: {}'.format(e))

Create/update resource

from txlib_too.api.resources import Resource
from txlib_too.http.exceptions import NotFoundError, ServerError

try:
    r = Resource.get(project_slug='project_slug', slug='resource_slug')
    # Resource exists, update it
    # Not all fields are allowed here. For example, if i18n_type
    # is provided, the request will fail with a 400 error
    try:
        r.save(content='{"key1": "text1"}')
    except ServerError as e:
        print('Exception while updating resource: {}'.format(e))

except NotFoundError:
    # Resource does not exist, create one now
    try:
        r = Resource(project_slug='project_slug', slug='resource_slug')
        r.save(name='R1', i18n_type='KEYVALUEJSON', content='{"key1": "text1"}')
    except ServerError as e:
        print('Exception while creating resource: {}'.format(e))

except ServerError as e:
    print('Exception while retrieving resource: {}'.format(e))

Alternatively, instead of passing all parameters to save(), you can do the following:

r = Resource.get(...)
r.name = '...'
r.i18n_type = '...'
r.content = '...'
r.save()

Translations

Get translation

from txlib_too.api.translations import Translation
from txlib_too.http.exceptions import NotFoundError, ServerError

try:
    t = Translation.get(project_slug='project_slug', slug='resource_slug', lang='translation_language')
    print(t.lang) # 'translation_language'
except NotFoundError:
    print('Translation not found')
except ServerError as e:
    print('Exception while retrieving translation: {}'.format(e))

Create/update translation

from txlib_too.api.translations import Translation
from txlib_too.http.exceptions import NotFoundError, ServerError

try:
    t = Translation(
        project_slug=project_slug, slug=resource_slug, lang=language_code
    )
    t.save(content=content)
except ServerError as e:
    print('Exception while retrieving translation: {}'.format(e))

Metadata

Release files for txlib-too 0.1.8

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

Source distribution (sdist)

Source distribution for txlib-too 0.1.8
File Size Uploaded
txlib_too-0.1.8.tar.gz 38.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for txlib-too 0.1.8
File Interpreter ABI Platform
txlib_too-0.1.8-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 79.0 kB

Release files / txlib_too-0.1.8.tar.gz

Download URL txlib_too-0.1.8.tar.gz
Size 38.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a799c36d05273429864a76414f644fb591c31b4188839b8e09f8e4796d2dc5d7
BLAKE2b-256 checksum
How to use checksums
401e9c9893554a4d2a1412d589d0c1fc4fef3ac2c35b2d0287f5f5d3687879d6
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 / txlib_too-0.1.8-py2.py3-none-any.whl

Download URL txlib_too-0.1.8-py2.py3-none-any.whl
Size 40.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
45931c380cc415a369daf2d99555c08648530966edb5a8ffb33970dab20f7f6b
BLAKE2b-256 checksum
How to use checksums
2747f383742fc5ec57521f2f898756749a62632fafd68380f3ab60e6051d1ca0
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 history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

1 release file

0.1.3

2 release files

0.1.2

2 release files

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