Skip to main content

Build Status Azure DevOps coverage

future-fstrings

A backport of fstrings to python<3.6.

Installation

pip install future-fstrings

Usage

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 main.py
hello world

Showing transformed source

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

$ future-fstrings-show main.py
# -*- 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 code.py > code_rewritten.py

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

Release files for future-fstrings 1.2.0

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

Source distribution (sdist)

Source distribution for future-fstrings 1.2.0
File Size Uploaded
future_fstrings-1.2.0.tar.gz 5.8 kB Details

Built distribution (wheel)

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

Total release size: 11.9 kB

Release files / future_fstrings-1.2.0.tar.gz

Download URL future_fstrings-1.2.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6cf41cbe97c398ab5a81168ce0dbb8ad95862d3caf23c21e4430627b90844089
BLAKE2b-256 checksum
How to use checksums
5de23874574cce18a2e3608abfe5b4b5b3c9765653c464f5da18df8971cf501d
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.32.1 CPython/3.6.7

Release files / future_fstrings-1.2.0-py2.py3-none-any.whl

Download URL future_fstrings-1.2.0-py2.py3-none-any.whl
Size 6.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
90e49598b553d8746c4dc7d9442e0359d038c3039d802c91c0a55505da318c63
BLAKE2b-256 checksum
How to use checksums
ab6dea1d52e9038558dd37f5d30647eb9f07888c164960a5d4daa5f970c6da25
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.32.1 CPython/3.6.7

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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