Standard-chunk
Standard-chunk is a Python library that redistributes modules, often referred to as 'dead batteries,' that have been removed from the Python standard library as per PEP 594 and PEP 632. It allows projects to continue using these modules (such as `aifc`, `asynchat`, `chunk`, `cgi`, etc.) by making them installable via pip. The library focuses on providing minimal compatibility support for these removed modules, rather than active development of new features, with releases typically aligning with Python's major version cycles.
Warnings
- breaking The primary `chunk` module was officially removed from the Python standard library in Python 3.13. Without `standard-chunk` installed, `import chunk` will raise an `ImportError` on Python 3.13 and newer versions.
- gotcha The `distutils` module, also redistributed by `python-deadlib` (the upstream project for `standard-chunk`), is explicitly noted as 'Not working on Python 3.13'. While `standard-chunk` provides the `chunk` module, users depending on other dead batteries should check specific compatibility notes.
- gotcha This library is intended for compatibility with removed standard library modules. It explicitly states it does NOT accept new features or anything beyond minimal compatibility work. Attempting to contribute new features or significant changes will likely be rejected.
- gotcha As 'dead batteries', the modules provided by `standard-chunk` are not actively maintained for new features or modern best practices. They are provided as-is for compatibility and might not integrate well with contemporary Python ecosystems.
Install
-
pip install standard-chunk
Imports
- chunk
import chunk
Quickstart
import io
import chunk
# Simulate a file-like object with some IFF-like data
# (simplified for demonstration, actual IFF files are more complex)
iff_data = b'FORM\x00\x00\x00\x18TESTCHANKS\x00\x00\x00\x08DATA\x00\x00\x00\x04abcd'
f = io.BytesIO(iff_data)
try:
# Create a Chunk object from a file-like object
ck = chunk.Chunk(f)
print(f"Chunk ID: {ck.getname().decode('ascii')}")
print(f"Chunk Size: {ck.getsize()}")
# Read some data from the chunk
data_read = ck.read(4)
print(f"Data read: {data_read}")
# Seek within the chunk
ck.seek(0)
data_read_again = ck.read(4)
print(f"Data read again after seek: {data_read_again}")
ck.close()
except Exception as e:
print(f"An error occurred: {e}")
# Example for another 'dead battery' module, asyncore
# try:
# import asyncore
# print("asyncore imported successfully.")
# except ImportError:
# print("asyncore not found, install standard-asyncore if needed.")