Skip to main content

Python BiDi

https://badge.fury.io/py/python-bidi.png https://travis-ci.org/MeirKriheli/python-bidi.png?branch=master

Bi-directional (BiDi) layout implementation in pure python

Package documentation

API

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

Required arguments:

  • unicode_or_str: The original 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 encoding. 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).

  • base_dir: ‘L’ or ‘R’, override the calculated base_level.

  • 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           Output to stderr steps taken with the algorithm
  -b BASE_DIR, --base-dir=BASE_DIR
                        Override base direction [L|R]

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 setup.py test

Some explicit tests are failing right now (see TODO)

0.4.2

  • Type Fixes, thanks jwilk

History

0.4.1

  • Merged Fix for mixed RTL and numbers, Thanks Just van Rossum

0.4.0

  • Move to cookiecutter template

  • Python 3 support (py2.6, 2.7, 3.3, 3.4 and pypy)

  • Better docs

  • Travis integration

  • Tox tests

  • PEP8 cleanup

0.3.4

  • Remove extra newline in console script output

0.3.3

  • Implement overriding base paragraph direction

  • Allow overriding base direction in pybidi console script

  • Fix returning display in same encoding

0.3.2

  • Test for surrogate pairs

  • Fix indentation in documentations

  • Specify license in setup.py

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

Metadata

Release files for python-bidi 0.4.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 python-bidi 0.4.2
File Size Uploaded
python-bidi-0.4.2.tar.gz 40.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-bidi 0.4.2
File Interpreter ABI Platform
python_bidi-0.4.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 71.2 kB

Release files / python-bidi-0.4.2.tar.gz

Download URL python-bidi-0.4.2.tar.gz
Size 40.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5347f71e82b3e9976dc657f09ded2bfe39ba8d6777ca81a5b2c56c30121c496e
BLAKE2b-256 checksum
How to use checksums
7b253372ce50082776134b0467a4616722ff7494f3bcd9cf11e1180d0eddb248
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3

Release files / python_bidi-0.4.2-py2.py3-none-any.whl

Download URL python_bidi-0.4.2-py2.py3-none-any.whl
Size 30.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
50eef6f6a0bbdd685f9e8c207f3c9050f5b578d0a46e37c76a9c4baea2cc2e13
BLAKE2b-256 checksum
How to use checksums
33b0f942d146a2f457233baaafd6bdf624eba8e0f665045b4abd69d1b62d097d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.4

1 release file

0.3.3

2 release files

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

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