Skip to main content

BiDi layout implementation in pure python

Project description

python-bidi

Bi-directional (BiDi) layout implementation in pure python

API

The algorithm starts with a single entry point bidi.algorithm.get_display.

Required arguments:

  • unicode_or_str: The orginal unicode or string (i.e: storage). If it’s a string use the optional argument encoding to specify it’s encoding.

Optional arguments:

  • encoding: If unicode_or_str is a string, specifies the encdoing. The algorithm uses unicodedata which requires unicode. This encoding will be used to decode and encode back to string before returning (default: “utf-8”).

  • upper_is_rtl: True to treat upper case chars as strong ‘R’ for debugging (default: False).

  • debug: True to display (using sys.stderr) the steps taken with the algorithm (default: False).

Returns the display layout, either as unicode or encoding encoded string (depending on the type of unicode_or_str').

Example:

>>> from bidi.algorithm import get_display
>>> get_display(u'car is THE CAR in arabic', upper_is_rtl=True)
u'car is RAC EHT in arabic'

CLI

pybidi is a command line utility (calling bidi.main) for running the bidi algorithm. the script can get a string as a parameter or read text from stdin. Usage:

$ pybidi -h
Usage: pybidi [options]

Options:
  -h, --help            show this help message and exit
  -e ENCODING, --encoding=ENCODING
                        Text encoding (default: utf-8)
  -u, --upper-is-rtl    treat upper case chars as strong 'R' for debugging
                        (default: False).
  -d, --debug           Display the steps taken with the algorithm

Examples:

$ pybidi -u 'car is THE CAR in arabic'
car is RAC EHT in arabic

$ cat ~/Documents/example.txt | pybidi
...

Installation

See docs/INSTALL.rst

Running tests

To run the tests:

python -m bidi.tests

Some explicit tests are failing right now (see TODO)

Changelog

0.3.1

  • Added missing description

  • docs/INSTALL.rst

0.3

  • Apply bidi mirroring

  • Move to back function based implementation

0.2

  • Move the algorithm to a class based implementation

0.1

  • Initial release

TODO

  • Some explicit tests are failing

  • Arabic shaping

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

python-bidi-0.3.1.tar.gz (29.2 kB view details)

Uploaded Source

File details

Details for the file python-bidi-0.3.1.tar.gz.

File metadata

  • Download URL: python-bidi-0.3.1.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for python-bidi-0.3.1.tar.gz
Algorithm Hash digest
SHA256 cca2f5d9f4bf99dc55cbb1a9731883a36032a19c9c2a3d042d2748abcaca969f
MD5 662d16b18f03c7a6eae7a4884bdf8f2f
BLAKE2b-256 a29818e0f5343ff8f0008f50b66a50f69c6ff877bcdb2d7a0fc8c9d2b8864771

See more details on using hashes here.

Supported by

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