{"id":2799,"library":"tables","title":"PyTables (Hierarchical Datasets)","description":"PyTables is a Python library for managing hierarchical datasets, designed for efficient handling of extremely large amounts of data. It builds on the HDF5 library and NumPy, providing high-performance I/O for scientific data. The current version is 3.11.1, and it maintains an active release cadence with regular updates.","status":"active","version":"3.11.1","language":"python","source_language":"en","source_url":"https://github.com/PyTables/PyTables","tags":["data science","hdf5","array","storage","scientific computing","large data"],"install":[{"cmd":"pip install tables","lang":"bash","label":"Install PyTables"}],"dependencies":[{"reason":"Fundamental for array operations and defining data structures.","package":"numpy","optional":false}],"imports":[{"note":"The primary module for PyTables.","symbol":"tables","correct":"import tables"},{"note":"As of PyTables 3.10.0, the `open_file` function (snake_case) is the preferred method for opening HDF5 files, aligning with Python style guides. `openFile` (camelCase) is still supported but discouraged.","wrong":"tables.openFile","symbol":"open_file","correct":"tables.open_file"},{"note":"Base class for defining the structure (description) of tables.","symbol":"IsDescription","correct":"tables.IsDescription"}],"quickstart":{"code":"import tables as tb\nimport numpy as np\nimport os\n\n# Define a table description\nclass MyTableDescription(tb.IsDescription):\n    col1 = tb.StringCol(16, pos=1)\n    col2 = tb.Int32Col(pos=2)\n    col3 = tb.Float64Col(pos=3)\n\nfilename = \"mytable.h5\"\nif os.path.exists(filename):\n    os.remove(filename)\n\ntry:\n    # Open the HDF5 file in write mode\n    with tb.open_file(filename, mode=\"w\", title=\"Test File\") as h5f:\n        # Create a group for organization\n        group = h5f.create_group(h5f.root, \"data\")\n\n        # Create a table within the group\n        table = h5f.create_table(group, 'table1', MyTableDescription, \"My First Table\")\n\n        # Append data to the table\n        table.append([(\"row_a\", 1, 1.1), (\"row_b\", 2, 2.2)])\n        table.flush() # Ensure data is written to disk\n\n        print(\"\\nData in table1 after first append:\")\n        for row in table.iterrows():\n            print(f\"  col1: {row['col1']}, col2: {row['col2']}, col3: {row['col3']}\")\n\n        # Add more data\n        table.append([(\"row_c\", 3, 3.3), (\"row_d\", 4, 4.4)])\n        table.flush()\n\n        print(\"\\nAll data in table1 (as NumPy record array):\")\n        print(table[:]) # Read all data into a NumPy record array\n\n    print(f\"\\nSuccessfully created and written to {filename}\")\n\n    # Re-open the file in read mode to verify\n    with tb.open_file(filename, mode=\"r\") as h5f_read:\n        read_table = h5f_read.root.data.table1\n        print(\"\\nData read from file:\")\n        for row in read_table.iterrows():\n            print(f\"  col1: {row['col1']}, col2: {row['col2']}, col3: {row['col3']}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Clean up the created file\n    if os.path.exists(filename):\n        os.remove(filename)\n        print(f\"Cleaned up {filename}\")","lang":"python","description":"This quickstart demonstrates how to create an HDF5 file, define a table structure using `IsDescription`, create a table, append data, and read data using PyTables. It also shows the importance of using context managers (`with`) for file handling to ensure proper closing."},"warnings":[{"fix":"Update code that relies on the return value of these methods. Access the newly renamed or moved node through its parent group or by directly referring to its new path.","message":"The `File.rename_node()` and `File.move_node()` methods no longer return the new node. They now return `None`.","severity":"breaking","affected_versions":">=3.7.0"},{"fix":"Instead of `obj=MyObject`, use `description=MyDescriptionClass` with a `tables.IsDescription` subclass to define the table's structure. This improves clarity and consistency.","message":"The `obj` argument for `File.create_table()` is deprecated.","severity":"deprecated","affected_versions":">=3.10.0"},{"fix":"If specific compression ratios or performance characteristics are critical, explicitly set the `complevel` parameter within the `Filters` object when creating extendable arrays (EArray) or tables with compression enabled.","message":"The default compression level for `zlib` and `blosc` filters changed from `zlib.Z_DEFAULT_COMPRESSION` to `1`.","severity":"gotcha","affected_versions":">=3.5.0"},{"fix":"Use a `with tables.open_file(...) as h5f:` statement, which automatically handles closing the file even if errors occur. Alternatively, explicitly call `h5f.close()` when the file is no longer needed.","message":"Always ensure `tables.File` objects are properly closed to prevent data corruption, resource leaks, or incomplete writes.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'3.11.1':43 'activ':48 'amount':20 'array':57 'build':24 'cadenc':50 'comput':60 'current':40 'data':22,38,54,62 'dataset':3,12 'design':13 'effici':15 'extrem':18 'handl':16 'hdf5':27,56 'hierarch':2,11 'high':33 'high-perform':32 'i/o':35 'larg':19,61 'librari':8,28 'maintain':46 'manag':10 'numpi':30 'perform':34 'provid':31 'pytabl':1,4 'python':7 'regular':52 'releas':49 'scienc':55 'scientif':37,59 'storag':58 'updat':53 'version':41","created_at":"2026-04-11T01:43:17.050578+00:00","updated_at":"2026-04-16T22:39:25.841617+00:00","problems":[{"fix":"Install the HDF5 development package for your OS: `sudo apt-get install libhdf5-dev` (Debian/Ubuntu), `sudo yum install hdf5-devel` (CentOS/RHEL), or `brew install hdf5` (macOS) before running `pip install tables`.","cause":"PyTables requires the HDF5 C library development headers to be installed on your system for successful compilation during `pip install`.","error":"fatal error: hdf5.h: No such file or directory"},{"fix":"Install the library using pip: `pip install tables`. If installation fails, address any underlying HDF5 dependency issues first.","cause":"The `tables` library or its dependencies were not installed successfully or are not accessible in the current Python environment.","error":"ModuleNotFoundError: No module named 'tables'"},{"fix":"Ensure the file specified is a properly created HDF5 file; verify its integrity, or create a new one using `tables.open_file()`.","cause":"You are attempting to open a file that is either corrupted, empty, or not a valid HDF5 file recognized by PyTables.","error":"IOError: unable to open file (file is not an HDF5 file)"},{"fix":"Check the existing structure of your HDF5 file using `file.walk_nodes()` or `file.root._v_children` to find the correct path.","cause":"You are trying to access a node (group or array) within the HDF5 file using a path that does not exist in the file's structure.","error":"KeyError: 'group path does not exist'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"3.11.1","cli_name":"ptdump","cli_version":"usage: ptdump [-h] [-v] [-d] [-a] [-s] [-c] [-i] [-R RANGE]","type":"library","homepage":"http://www.pytables.org","github":"https://github.com/PyTables/PyTables","docs":"http://www.pytables.org","changelog":"http://www.pytables.org/release_notes.html","pypi":"https://pypi.org/project/tables/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","serialization","database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}