Skip to main content

Interpy = Python String Interpolation

Interpy extends Python to support Ruby like string interpolation #{}. Quick example: print "Hello #{your_name}"

It is hightly optimized, and directly compiled to bytecode, so you will have the same Python speed when using it.

Installation

The installation of this package is quite simple, you only have to run pip install interpy.

Usage

All python files with string interpolation must have the following first line

# coding: interpy

Example:

# coding: interpy

package = "Interpy"
print "Enjoy #{package}!"

How it works

This package is inspired in Dropbox `pyxl template engine`_.

Parsing

Interpy uses support for specifying source code encodings as described in PEP 263 to do what it does. The functionality was originally provided so that python developers could write code in non-ascii languages (eg. chinese variable names). Interpy creates a custom encoding called interpy which allows it to convert interpolated strings into regular python before the file is compiled. Once the interpy codec is registered, any file starting with # coding: interpy is run through the interpy parser before compilation.

Compiling

The above example would be compiled to this (in bytecode):

# coding: interpy

package = "Interpy"
print "Enjoy "+str(package)+"!"

Compatibility

This package is fully compatible with Python 2+, Python 3+ and PyPy

Why?

I really enjoyed Ruby String interpolation, and "".format(...) or "" % (...) seems very verbose to me. I’m lazy by nature ;)

Metadata

Release files for interpy 1.1

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

Source distribution (sdist)

Source distribution for interpy 1.1
File Size Uploaded
interpy-1.1.tar.gz 9.7 kB Details

Release files / interpy-1.1.tar.gz

Download URL interpy-1.1.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b758d973a01beb7629c0d911ba051e975a576aa8fe21645a17e6197e1cdee058
BLAKE2b-256 checksum
How to use checksums
3c1d9ed213a6beb6ae3dbf312da4f1f78531713f88c6a06504ec07844c08ecdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.1 This release

1 release file

1.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