{"id":489,"library":"future","title":"Python-Future","description":"future is the missing compatibility layer between Python 2 and Python 3. It allows you to use a single, clean Python 3.x-compatible codebase to support both Python 2 and Python 3 with minimal overhead. It provides `future` and `past` packages with backports and forward ports of features from Python 3 and 2, and includes `futurize` and `pasteurize` scripts for automated code conversion. The latest version is 1.0.0, and while feature development is complete, it supports Python 3.12.","status":"maintenance","version":"1.0.0","language":"python","source_language":"en","source_url":"https://github.com/PythonCharmers/python-future","tags":["python2","python3","compatibility","migration","backport","futurize","pasteurize","six","2to3"],"install":[{"cmd":"pip install future","lang":"bash","label":"Install stable version"},{"cmd":"pip install future  # Requires Python >=2.6, !=3.0.*, !=3.1.*, !=3.2.*","lang":"bash","label":"Python compatibility"}],"dependencies":[],"imports":[{"note":"While `future.builtins` exists, the recommended pattern for Python 2/3 compatibility is `from builtins import ...` as it directly maps to Python 3 builtins on Py2 and has no effect on Py3. The wildcard `*` is shown in some examples for brevity but explicit imports are generally preferred.","wrong":"from future.builtins import *","symbol":"Builtins","correct":"from builtins import (bytes, dict, int, list, object, range, str,\n                       ascii, chr, hex, input, next, oct, open, pow,\n                       round, super, filter, map, zip)"},{"note":"This function makes Python 3-style standard library imports (e.g., `urllib.parse`, `queue`) available on Python 2 by modifying `sys.modules` and other mechanisms.","wrong":"import urllib.parse  # Directly on Py2 without aliases","symbol":"StandardLibraryAliases","correct":"from future.standard_library import install_aliases\ninstall_aliases()"},{"note":"These are built-in Python future statements crucial for enabling Python 3 behavior in Python 2. `future`'s tools and runtime patches complement these.","symbol":"__future__ imports","correct":"from __future__ import (absolute_import, division, print_function, unicode_literals)"},{"note":"Provides Python 2-specific builtins (like `basestring` or `unicode` type) on Python 3 for modules that explicitly need them, typically during module-by-module migration.","symbol":"past.builtins","correct":"from past.builtins import basestring, unicode"}],"quickstart":{"code":"from __future__ import (absolute_import, division, print_function, unicode_literals)\nfrom builtins import *\nfrom future.standard_library import install_aliases\ninstall_aliases()\n\n# Now write Python 3 code that runs on both Py2 and Py3\nprint(\"Hello, world!\")\n\ndef divide(a, b):\n    return a / b # Will use float division even on Python 2\n\nmy_dict = {'a': 1, 'b': 2}\nprint(list(my_dict.keys())) # dict.keys() returns a view (iterable) on Py2 with future installed\n\n# Example of Python 3 library name working on Py2\nimport urllib.request\nprint(urllib.request.urlopen('http://example.com').getcode())","lang":"python","description":"To write new code compatible with both Python 2 (2.6+) and Python 3 (3.3+), start each module with the essential `__future__` imports and `from builtins import *`. Then call `install_aliases()` to ensure standard library modules are correctly mapped. This allows writing predominantly Python 3-style code that runs on both versions."},"warnings":[{"fix":"Prioritize full migration to Python 3. `python-future` should be seen as a stepping stone or a compatibility layer for transitioning legacy code, not a long-term solution for Python 2 development.","message":"Python 2 reached its end-of-life in 2020. While `python-future` facilitates compatibility, relying on it for actively maintained Python 2 codebases is increasingly risky due to lack of Python 2 security updates and ecosystem support.","severity":"breaking","affected_versions":"<1.0.0 (and general Python 2 usage)"},{"fix":"For new Python 3 projects, write idiomatic Python 3 code directly. If compatibility with multiple Python 3 versions is needed, leverage `__future__` imports (native to Python) and `six` if strictly necessary for very old Python 3 versions, but prefer modern Python features.","message":"The `python-future` project is declared 'done' and is not recommended for new Python 3 projects. While it receives critical compatibility updates (e.g., Python 3.12 support), its primary purpose as a Python 2/3 compatibility layer means new feature development is complete. It should not be adopted as a dependency for greenfield Python 3 development.","severity":"gotcha","affected_versions":"All versions, especially 1.0.0+"},{"fix":"Use `install_aliases()` early in your application's startup. Be aware of potential conflicts, especially when mixing with other compatibility layers or dynamically loading modules. Consider explicit `future.moves` imports for specific items to limit global impact if issues arise.","message":"The `install_aliases()` function globally modifies `sys.modules` on Python 2 to map Python 3 standard library names. This can lead to unexpected behavior or conflicts if other libraries or custom import hooks make different assumptions about the module layout.","severity":"gotcha","affected_versions":"All versions on Python 2"},{"fix":"Prefer using `futurize` (for Py2 to Py2/3) or `pasteurize` (for Py3 to Py2/3) scripts for static code conversion. If `past.translation` is used, ensure thorough testing and be prepared for potential runtime issues.","message":"The `past.translation` module, which offers experimental automatic translation of Python 2 modules to Python 3 upon import, is in 'alpha' status and may be unstable or imperfect. Relying on it for critical functionality is not recommended.","severity":"deprecated","affected_versions":"All versions"},{"fix":"For HTTPS support on Python 2, especially within `urllib`, the documentation recommends using `from future.moves.urllib.request import urlopen` or using a dedicated HTTP library like `requests` that handles SSL/TLS more robustly.","message":"HTTPS support with the `http`-based backports within `future` is limited on Python 2.x due to significant changes in SSL support in Python 3.x. Direct `http`-based backports might fail for HTTPS connections.","severity":"gotcha","affected_versions":"All versions on Python 2.x"}],"env_vars":null,"last_verified":"2026-05-12T14:14:27.098Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"pip install future","cause":"The 'future' library is not installed in the Python environment where the code is being executed.","error":"ModuleNotFoundError: No module named 'future'"},{"fix":"pip install future","cause":"This error typically occurs in Python 2 when `from builtins import *` is used, but the 'future' library, which backports Python 3 builtins to Python 2, is not installed.","error":"ImportError: No module named builtins"},{"fix":"Upgrade your Python interpreter to version 3.7 or newer, or remove the `from __future__ import annotations` statement if it's not critical for older Python versions.","cause":"The `from __future__ import annotations` syntax, introduced by PEP 563, is only available from Python 3.7 onwards. This error occurs when trying to use it in an older Python version.","error":"SyntaxError: future feature annotations is not defined"},{"fix":"Upgrade your Python 2 interpreter to version 2.6 or newer, or ensure the code using this future import is not run on older Python 2 versions.","cause":"This error occurs in Python 2 when `from __future__ import print_function` is used with a Python 2 version older than 2.6, as the print function feature was introduced in Python 2.6.","error":"SyntaxError: future feature print_function is not defined"},{"fix":"Remove the 'L' suffix from integer literals. The `futurize` script from the 'future' library can help automate this conversion across your codebase by running `futurize -w your_script.py`.","cause":"Python 2 used an 'L' suffix (e.g., `1234L`) to denote long integers. Python 3 merged 'int' and 'long' types, making the 'L' suffix invalid syntax.","error":"SyntaxError: invalid syntax (with 'L' suffix on numbers)"}],"ecosystem":"pypi","meta_description":null,"install_score":80,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}