Skip to main content

Pies

PyPI version PyPi downloads Bitdeli Badge

The simplest (and tastiest) way to write one program that runs on both Python 2.6+ and Python 3.

Let’s eat some pies!

Installing pies

pip install pies

or if you prefer:

easy_install pies

Overview

Pies is a Python2 & 3 Compatibility layer with the philosophy that all code should be Python3 code. Starting from this viewpoint means that when running on Python3 pies adds virtually no overhead.

Instead of providing a bunch of custom methods (leading to Python code that looks out of place on any version) pies aims to back port as many of the Python3 api calls, imports, and objects to Python2 - Relying on special syntax only when absolutely necessary.

How does pies differ from six?

Pies is significantly smaller and simpler then six because it assumes for everything possible the developer is using the Python 3 compatible versions included with Python 2.6+, whereas six tries to maintain compatibility with Python 2.4 - leading to many more overrides and further into different language territory. Additionally, as stated above, where possible pies tries to enable you to not have to change syntax at all.

Integrating pies into your diet

Using and integrating pies into an existing Python 3+ code base (to achieve Python 2 & 3 dual support) couldn’t be simpler:

from __future__ import absolute_import, division, print_function, unicode_literals

from pies.overrides import *

Then simply write standard Python3 code, and enjoy Python2 Support.

Works Unchanged (The Good)

The best part of Pies is how much Python3 code works unchanged in Python2

Functions:

  • round

  • next

  • filter

  • map

  • zip

  • input

  • range

Types:

  • object (str automatically has correct behavior on all versions of Python)

  • chr (creates a unichr object in Python2)

  • str (creates a unicode object in Python2)

  • dict (creating a dict using dict() will give you all the special Python3 itemview results, but using {} will not)

Imports:

  • html

  • http

  • xmlrpc

  • _thread

  • builtins

  • configparser

  • copyreg

  • queue

  • reprlib

  • socketserver

  • ipaddress

  • argparse

  • enum (also adds this library to Python 3.0-3.3)

Different Imports (The Bad)

Some Python3 Modules have moved around so much compared to their Python2 counterpart, that I found it necessary to create special versions of them to obtain the Python3 naming on both environments. Since these modules exist already in Python2 allowing them to be imported by the Python3 module name directly is not possible. Instead, you must import these modules from pies.

Example:

form pies import pickle

Full List:

  • dbm

  • urllib

  • collections

  • functools

  • imp

  • itertools

  • pickle

  • StringIO

  • sys

  • unittest

Special Syntax (The Ugly)

Sadly, there is still special syntax that is present for corner cases.

  • PY2 - True if running on Python2

  • PY3 - True if running on Python3

  • u(‘text’) - should replace u’text’ made available for ease of porting code from Python2

  • itemsview(collection) - should replace collection.iteritems() where you do not control the collection passed in

  • valuesview(collection) - should replace collection.values() where you do not control the collection passed in

  • keysview(collection) - should replace collection.keys() where you do not control the collection passed in

  • execute() - enables Python 3 style exec statements on both environments.

  • integer_types - may want to use isinstance(variable, integer_types) instead of type(variable, int) as long values will not match int in Python2.

  • NewClass(with_metaclass(metaclass, parent_class)) - Should replace both “metaclass = metaclass” and “NewClass(metaclass=metaclass)” as a way to assign meta-classes.

What Could be Improved?

I’m pretty sure a bunch. If you run into any problems or have any ideas please don’t hesitate to file a bug, submit a pull request, or email me at timothy.crosley@gmail.com.


Thanks and I hope you enjoy pies!

~Timothy Crosley

Release files for pies 2.5.5

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

Source distribution (sdist)

Source distribution for pies 2.5.5
File Size Uploaded
pies-2.5.5.tar.gz 10.7 kB Details

Built distribution (wheel)

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

Total release size: 26.2 kB

Release files / pies-2.5.5.tar.gz

Download URL pies-2.5.5.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
35de200a5a65446d6d6eeb8d8dce4b87c5e31ab517864cc6b01bbda15f3da3bb
BLAKE2b-256 checksum
How to use checksums
a492cb03bce58b9837d13a6345cd8d2fe90194c0f21dcaf9899e18153437a46d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pies-2.5.5-py2.py3-none-any.whl

Download URL pies-2.5.5-py2.py3-none-any.whl
Size 15.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
03e51d223d1a11797e257f2a2917b93b29b7179f45db11db2cf41599d5beb1f4
BLAKE2b-256 checksum
How to use checksums
6e6ea96440193fe9ac3f25dbaa3e1b1c46bde74d9b3bb2a1f17199320d33efd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

2.6.7

2 release files

2.6.5

2 release files

2.6.3

1 release file

2.6.2

1 release file

2.6.1

1 release file

2.6.0

2 release files

This release

2.5.5 This release

2 release files

2.5.4

2 release files

2.5.3

2 release files

2.5.2

2 release files

2.5.1

2 release files

2.5.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

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