Skip to main content

Add Python 3 support to Python 2 applications using the six module.

Project description

sixer is a tool adding Python 3 support to a Python 2 project.

sixer was written to produces patches to port OpenStack to Python 3.

It uses basic regular expressions to find code which needs to be modified. It emits warnings when code was not patched or looks suspicious.

Usage <directory> <operation> displays the name of patched files. It displays warnings for code unchanged but which looks suspicious.

Warning: modifies files inplace without asking for confirmation. It’s better to use it in a project managed by a source control manager (ex: git).

Available operations:

  • iteritems

  • itervalues

  • long

  • next

  • raise

  • unicode

  • xrange


To install sixer, type:

pip install sixer

sixer requires Python 3, it doesn’t work on Python 2.


  • iteritems:

    • replace dict.iteritems() with six.iteritems(dict)

  • itervalues:

    • replace dict.itervalues() with six.itervalues(dict)

  • long:

    • replace 123L with 123

    • octal number are unchanged (ex: 010L)

  • next:

    • replace with next(iter)

  • raise:

    • replace raise exc[0], exc[1], exc[2] with six.reraise(*exc)

    • replace raise exc_type, exc_value, exc_tb with six.reraise(exc_type, exc_value, exc_tb)

    • replace raise exc, msg with raise exc(msg)

  • unicode:

    • replace unicode with six.text_type

  • xrange:

    • replace xrange() with range() and add from six.moves import range

Adding the six import

When an operation uses six, import six may be added. sixer repects OpenStack coding style rules to add the import: imports grouped by standard library, third party and local imports; and imports must be are sorted.

The sixer tool was initially written to produce patches for OpenStack which respects OpenStack coding style, especially the complex rule to group and sort imports.


The project is based on regular expressions, it produces false positives (invalid changes). For example, some operations replace patterns in strings, comments or function names even if it doesn’t make sense.

Try also the 2to6 project which may be more reliable.


To run tests, type tox. Type pip install tox to install the tox program.

Or run tests manually: type python3


  • 2015-05-12: Version 0.2, first public release

See also

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

sixer-0.2.tar.gz (12.5 kB view hashes)

Uploaded source

Built Distribution

sixer-0.2-py3-none-any.whl (8.6 kB view hashes)

Uploaded 3 4

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page