all Python 3until 3.13Removed from the standard libraryterm
xdrlib
removed modules
Pack data into the XDR format (RFC 1014) used by Sun RPC and NFS. Removed in Python 3.13 — use struct with a big-endian format.
Syntax
import xdrlib # до 3.13
xdrlib.Packer() collected values into a buffer: pack_int(), pack_double(), pack_string() — and get_buffer() returned the bytes; Unpacker(data) read them back. PEP 594 dropped it: XDR lives almost only in Sun RPC and NFS, which have no Python clients in the stdlib. How to port: XDR is big-endian with 4-byte alignment, so struct.pack('>i', n) replaces pack_int, struct.pack('>d', x) pack_double, and a string is packed as a '>I' length followed by the bytes padded with zeros to a multiple of four. Reading back is struct.unpack with the same formats. The standard-xdrlib package on PyPI restores the module.
Examples
# Python 3.13+
try:
import xdrlib
except ModuleNotFoundError as e:
print(type(e).__name__) # → ModuleNotFoundError
# Python 3.13+
import struct
def pack_string(s):
return struct.pack('>I', len(s)) + s + bytes(-len(s) % 4)
data = struct.pack('>i', 1) + pack_string(b'ab')
print(data.hex()) # → 000000010000000261620000
import xdrlib
p = xdrlib.Packer()
p.pack_int(1)
p.pack_string(b'ab')
print(p.get_buffer().hex()) # → 000000010000000261620000
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy