Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

A backport of fstrings to python<3.6

Project description

Build Status Azure DevOps coverage


A backport of fstrings to python<3.6.


pip install future-fstrings


Include the following encoding cookie at the top of your file (this replaces the utf-8 cookie if you already have it):

# -*- coding: future_fstrings -*-

And then write python3.6 fstring code as usual!

# -*- coding: future_fstrings -*-
thing = 'world'
print(f'hello {thing}')
$ python2.7
hello world

Showing transformed source

future-fstrings also includes a cli to show transformed source.

$ future-fstrings-show
# -*- coding: future_fstrings -*-
thing = 'world'
print('hello {}'.format((thing)))

Transform source for micropython

The future-fstrings-show command can be used to transform source before distributing. This can allow you to write f-string code but target platforms which do not support f-strings, such as micropython.

To use this on modern versions of python, install using:

pip install future-fstrings[rewrite]

and then use future-fstrings-show as above.

For instance:

future-fstrings-show >

How does this work?

future-fstrings has two parts:

  1. A utf-8 compatible codec which performs source manipulation
    • The codec first decodes the source bytes using the UTF-8 codec
    • The codec then leverages tokenize-rt to rewrite f-strings.
  2. A .pth file which registers a codec on interpreter startup.

you may also like

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for future-fstrings, version 1.2.0
Filename, size File type Python version Upload date Hashes
Filename, size future_fstrings-1.2.0-py2.py3-none-any.whl (6.1 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size future_fstrings-1.2.0.tar.gz (5.8 kB) File type Source Python version None Upload date Hashes View

Supported by

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