{"id":6715,"library":"mda-xdrlib","title":"mda-xdrlib","description":"mda-xdrlib is a stand-alone Python module that provides the functionality of the `xdrlib` module, as it existed in CPython 3.10.8. It enables conversion between Python data types and the XDR (External Data Representation) format, which is useful for platform-independent binary data exchange. Currently at version 0.2.0, its releases are infrequent and primarily driven by the need to maintain XDR compatibility for projects like MDAnalysis after the standard library's `xdrlib` module was deprecated.","status":"active","version":"0.2.0","language":"en","source_language":"en","source_url":"https://github.com/MDAnalysis/mda-xdrlib","tags":["XDR","serialization","data format","MDAnalysis","deprecated-stdlib-replacement","binary-protocol"],"install":[{"cmd":"pip install mda-xdrlib","lang":"bash","label":"pip"}],"dependencies":[],"imports":[{"note":"The standard 'xdrlib' module is deprecated in Python 3.11 and removed in 3.13; use 'mda_xdrlib' as a standalone replacement for newer Python versions.","wrong":"from xdrlib import Packer","symbol":"Packer","correct":"from mda_xdrlib import Packer"},{"note":"The standard 'xdrlib' module is deprecated in Python 3.11 and removed in 3.13; use 'mda_xdrlib' as a standalone replacement for newer Python versions.","wrong":"from xdrlib import Unpacker","symbol":"Unpacker","correct":"from mda_xdrlib import Unpacker"}],"quickstart":{"code":"import mda_xdrlib\n\n# 1. Pack data\npacker = mda_xdrlib.Packer()\npacker.pack_int(123)\npacker.pack_string(b\"hello xdr\")\npacker.pack_double(3.14159)\npacked_data = packer.get_buffer()\nprint(f\"Packed data (hex): {packed_data.hex()}\")\n\n# 2. Unpack data\nunpacker = mda_xdrlib.Unpacker(packed_data)\nunpacked_int = unpacker.unpack_int()\nunpacked_string = unpacker.unpack_string()\nunpacked_double = unpacker.unpack_double()\nunpacker.done() # Verify all data has been unpacked\n\nprint(f\"Unpacked int: {unpacked_int}\")\nprint(f\"Unpacked string: {unpacked_string.decode('utf-8')}\")\nprint(f\"Unpacked double: {unpacked_double}\")","lang":"python","description":"Demonstrates basic XDR packing of an integer, a string, and a double, followed by unpacking them in the correct order."},"warnings":[{"fix":"Switch imports from `import xdrlib` to `import mda_xdrlib`. Ensure your codebase explicitly uses `mda_xdrlib`.","message":"The `xdrlib` module in the Python standard library is deprecated in Python 3.11 and will be removed entirely in Python 3.13. `mda-xdrlib` serves as a drop-in replacement, and users on Python 3.11+ must use this standalone package or similar solutions to retain `xdrlib` functionality.","severity":"deprecated","affected_versions":"Python 3.11+"},{"fix":"Globally replace `import xdrlib` with `import mda_xdrlib` (and similar for specific classes like `Packer` or `Unpacker`).","message":"For projects previously using the standard `xdrlib` module (especially those developed with Python versions prior to 3.11), migrating to `mda-xdrlib` requires updating all import statements to `from mda_xdrlib import ...` instead of `from xdrlib import ...`.","severity":"breaking","affected_versions":"<=0.2.0 (when migrating from stdlib xdrlib)"},{"fix":"Carefully consult the Python 3.10 standard library documentation for `xdrlib` for detailed API usage and best practices. Implement robust error handling (try-except `mda_xdrlib.Error`).","message":"The XDR format and its Python API (`xdrlib`/`mda-xdrlib`) can be unintuitive for developers accustomed to more modern serialization formats. Incorrect usage of packing/unpacking methods (e.g., mismatching types or order) or improper buffer management (e.g., `get_position`, `set_position`) can lead to `mda_xdrlib.Error` or `mda_xdrlib.ConversionError`.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure that file handling is robust, particularly for frequently accessed or modified auxiliary files. Implement proper locking or synchronization mechanisms if files are accessed concurrently across multiple processes or threads. Consider regenerating potentially corrupted offset files if errors persist.","message":"When `mda-xdrlib` is used by other libraries (e.g., MDAnalysis for reading GROMACS XDR files), issues can arise from external factors such as corrupted auxiliary files (e.g., offset files) or concurrent access in multiprocessing environments. These can manifest as `ValueError` (e.g., for pickled data) or other file I/O errors.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}