{"id":3279,"library":"standard-aifc","title":"Standard Library `aifc` Redistribution","description":"standard-aifc is a redistribution of the `aifc` module, which was part of the Python standard library until its removal in Python 3.13. It provides functionality for reading and writing AIFF (Audio Interchange File Format) and AIFF-C files. Maintained by the `python-deadlib` project, its purpose is to make these removed 'dead batteries' available via PyPI for continued compatibility. The current version is 3.13.0, representing a re-packaging effort rather than active feature development.","status":"maintenance","version":"3.13.0","language":"en","source_language":"en","source_url":"https://github.com/youknowone/python-deadlib","tags":["audio","aiff","aifc","standard library","audio format","dead batteries"],"install":[{"cmd":"pip install standard-aifc","lang":"bash","label":"Install `standard-aifc`"}],"dependencies":[],"imports":[{"note":"The `standard-` prefix is for the package name on PyPI; the module itself imports as `aifc` because it is a direct redistribution of the standard library module.","wrong":"from standard_aifc import aifc","symbol":"aifc","correct":"import aifc"},{"note":"Importing `*` from `aifc` will shadow the built-in `open()` function, leading to unexpected errors, as `aifc.open` has different argument expectations.","wrong":"from aifc import *; open('file.aiff', 'rb')","symbol":"open","correct":"aifc.open('file.aiff', 'rb')"}],"quickstart":{"code":"import aifc\nimport os\n\noutput_file = \"test_audio.aiff\"\n\n# Parameters for a dummy AIFF file\nnchannels = 1  # Mono\nsampwidth = 2  # 2 bytes per sample (16-bit)\nframerate = 44100  # 44.1 kHz\nnframes = 44100 * 1  # 1 second of audio\n\ntry:\n    # 1. Create a dummy AIFF file\n    with aifc.open(output_file, 'wb') as af:\n        af.setnchannels(nchannels)\n        af.setsampwidth(sampwidth)\n        af.setframerate(framerate)\n        af.setnframes(nframes)\n        # Write dummy silent frames\n        dummy_frame = b'\\x00' * (nchannels * sampwidth)\n        af.writeframes(dummy_frame * nframes)\n\n    print(f\"Created dummy AIFF file: {output_file}\")\n\n    # 2. Read parameters from the created AIFF file\n    with aifc.open(output_file, 'rb') as af_read:\n        print(f\"\\nReading from {output_file}:\")\n        print(f\"  Channels: {af_read.getnchannels()}\")\n        print(f\"  Sample width (bytes): {af_read.getsampwidth()}\")\n        print(f\"  Frame rate (Hz): {af_read.getframerate()}\")\n        print(f\"  Number of frames: {af_read.getnframes()}\")\n        print(f\"  Compression type: {af_read.getcomptype().decode('utf-8')}\")\n\nexcept aifc.Error as e:\n    print(f\"An aifc error occurred: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\nfinally:\n    # Clean up the dummy file\n    if os.path.exists(output_file):\n        os.remove(output_file)\n        print(f\"Cleaned up {output_file}\")","lang":"python","description":"This quickstart demonstrates how to create a simple AIFF file with dummy audio data and then read its audio parameters using the `aifc` module."},"warnings":[{"fix":"Install `standard-aifc` via pip to restore the module's functionality in Python 3.13+.","message":"The original `aifc` module was removed from the Python standard library starting with Python 3.13. Direct `import aifc` will fail in Python 3.13+ environments unless `standard-aifc` (or an equivalent) is installed.","severity":"breaking","affected_versions":"Python 3.13+"},{"fix":"For new projects, consider modern audio processing libraries (e.g., `soundfile`, `pydub`) that are actively maintained and support more formats and features. Use `standard-aifc` only for maintaining compatibility with existing codebases.","message":"The `aifc` module was officially deprecated in the Python standard library from version 3.11, signaling its eventual removal. While `standard-aifc` provides a means to continue using it, it should be considered a legacy component.","severity":"deprecated","affected_versions":"Python 3.11+, removed in 3.13+"},{"fix":"Always import the module as `import aifc` and access its functions via `aifc.open()`, `aifc.getnchannels()`, etc.","message":"Avoid `from aifc import *`. The `aifc` module defines its own `open()` function which, if imported unqualified, will shadow the built-in `open()` function, leading to unexpected behavior and errors when trying to open non-AIFF files.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Do not expect new features or proactive bug fixes. For robust, long-term audio processing, evaluate actively maintained third-party libraries.","message":"The `standard-aifc` package is a compatibility redistribution and is explicitly stated by its maintainers to not accept new features or anything beyond minimal compatibility work. It is not actively developed for new functionalities or extensive bug fixes.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure correct file modes are used when opening files. For parsing complex or non-standard AIFF/AIFF-C files, consider other libraries or pre-processing the files.","message":"The `aifc.open()` function is strict about file modes, only accepting `'r'`, `'rb'`, `'w'`, or `'wb'`. Using other modes (e.g., `'a'`) will result in an `aifc.Error`. Additionally, the module might not correctly parse AIFF/AIFF-C files with uncommon or malformed compression type headers (e.g., 'raw ' instead of 'NONE').","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}