Registry / serialization / future-fstrings

future-fstrings

JSON →
library1.2.0pypypi✓ verified 29d ago

Future F-strings is a library that backported f-string (formatted string literal) syntax to Python versions prior to 3.6. It enables developers to use f-strings in Python 2.7, and Python 3.3-3.5 environments by transforming the source code. The current version is 1.2.0, but the library is now deprecated as its target Python versions have reached end-of-life and MicroPython, a common target for its `rewrite` functionality, now supports f-strings natively.

pip install future-fstrings
INSTALL
IMPORT
SIG · FUTURE-FSTRINGS
F
future-fstrings
serializationpythonv1.2.0
Install
1.6s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Encoding Cookie
✓ # -*- coding: future_fstrings -*- # Your f-string code here
✗ import future_fstrings
The primary mechanism for enabling f-strings at runtime in older Python versions is an encoding cookie at the top of the file, not a direct Python import statement. However, `future_fstrings.register()` can be used in specific scenarios.
future_fstrings.register()
✓ import future_fstrings future_fstrings.register()
Used for manual registration of the codec in environments where normal .pth file site registration does not occur, such as AWS Lambda or when using PYTHONPATH.

This quickstart demonstrates two ways to use `future-fstrings`. The first shows how to enable f-strings at runtime in a Python < 3.6 environment using the special encoding cookie at the top of the file. The second explains how to use the `future-fstrings-show` command-line utility to transform the source code into Python 2/3.5 compatible format calls, which is useful for distribution to environments without `future-fstrings` installed.

# -*- coding: future_fstrings -*- import os name = os.environ.get('USER_NAME', 'world') message = f'Hello {name}!' print(message) # To demonstrate the CLI transformation (requires future-fstrings[rewrite]) # Save the above code as 'my_app.py' # Run in your shell: # future-fstrings-show my_app.py # This will output the Python2/3.5 compatible code (e.g., using .format())
Debug
Known issues
deprecatedThe `future-fstrings` library is officially deprecated by its maintainer. Python 2 and Python 3.5 (the target versions for runtime f-string support) have reached their end-of-life. Furthermore, MicroPython, a common target for its source transformation capabilities, now includes native f-string support. The library is no longer needed for its original purpose.
fix
Upgrade to Python 3.6+ or use native f-string support in MicroPython. If targeting very old Python versions is unavoidable, understand that the library is unmaintained.
affects: <= 1.2.0
gotchaThe automatic codec registration via a `.pth` file may not work in certain deployment environments (e.g., AWS Lambda, or when `PYTHONPATH` is used instead of truly installed packages). In such cases, the `future_fstrings.register()` function must be called explicitly before importing any modules that use f-strings.
fix
Manually register the codec by adding `import future_fstrings; future_fstrings.register()` at the entry point of your application before any f-string-using modules are imported.
affects: All versions
gotchaWhen using the encoding cookie, the entire file is decoded and rewritten at once. While generally robust, complex or very large files *could* theoretically encounter performance issues during the initial load due to this on-the-fly source manipulation.
fix
For very large files or performance-critical startup paths in Python < 3.6, consider pre-transforming the code using `future-fstrings-show` rather than relying on the runtime codec.
affects: All versions
Errors
Common errors & fixes
SyntaxError: invalid syntax
This error occurs when using f-strings (formatted string literals) in Python versions prior to 3.6 without the `future-fstrings` library correctly configured to backport the syntax. The interpreter does not recognize the 'f' prefix as valid string syntax.
fix
Ensure `future-fstrings` is installed (`pip install future-fstrings`) and add `# -*- coding: future_fstrings -*-` as the second line of your Python file to enable the codec, or use the `future-fstrings-show` command to transform your code for distribution: `future-fstrings-show your_script.py > rewritten_script.py`.
SyntaxError: unexpected EOF while parsing
This specific syntax error often arises when an f-string is incomplete or malformed (e.g., missing a closing brace or quote) in older Python environments that do not natively support f-strings, and `future-fstrings` is either not active or struggles to parse the incorrect f-string syntax during its transformation process.
fix
First, check for any unclosed parentheses, brackets, or quotes within your f-string or the line where the error occurs. If the f-string syntax is correct, ensure `future-fstrings` is installed (`pip install future-fstrings`) and the codec is enabled in your file with `# -*- coding: future_fstrings -*-`.
LookupError: unknown encoding: future_fstrings
This error happens when a Python file begins with `# -*- coding: future_fstrings -*-` but the `future-fstrings` package, which registers this custom codec with the interpreter, is not installed in the Python environment.
fix
Install the `future-fstrings` package using pip: `pip install future-fstrings`.
Upgrade
Version history
1.2.0latest on PyPI · released Jun 16, 2019
Audit
Dependencies
tokenize-rtrequiredUsed internally by the codec to rewrite f-strings.
Agent activity
10 hits · last 30 days
node
8
Amazon
1
Resources
future-fstrings — pip install future-fstrings · libregistry