Library Reference

PyTables implements several classes to represent the different nodes in the object tree. They are named File, Group, Leaf, Table, Array, CArray, EArray, VLArray and UnImplemented. Another one allows the user to complement the information on these different objects; its name is AttributeSet. Finally, another important class called IsDescription allows to build a Table record description by declaring a subclass of it. Many other classes are defined in PyTables, but they can be regarded as helpers whose goal is mainly to declare the data type properties of the different first class objects and will be described at the end of this chapter as well.

An important function, called openFile is responsible to create, open or append to files. In addition, a few utility functions are defined to guess if the user supplied file is a PyTables or HDF5 file. These are called isPyTablesFile() and isHDF5File(), respectively. There exists also a function called whichLibVersion() that informs about the versions of the underlying C libraries (for example, HDF5 or Zlib) and another called print_versions() that prints all the versions of the software that PyTables relies on. Finally, test() lets you run the complete test suite from a Python console interactively.

Let’s start discussing the first-level variables and functions available to the user, then the different classes defined in PyTables.

tables variables and functions

Global variables

Global functions

The File Class

File properties

File methods - file handling

File methods - hierarchy manipulation

File methods - tree traversal

File methods - Undo/Redo support

File methods - attribute handling

The Node class

Node instance variables - location dependent

Node instance variables - location independent

Node instance variables - attribute shorthands

Node methods - hierarchy manipulation

Node methods - attribute handling

The Group class

Group properties

Group methods

Important

Caveat: The following methods are documented for completeness, and they can be used without any problem. However, you should use the high-level counterpart methods in the File class (see The File Class, because they are most used in documentation and examples, and are a bit more powerful than those exposed here.

The following methods are provided in addition to those in Node (see The Node class):

Group special methods

Following are described the methods that automatically trigger actions when a Group instance is accessed in a special way.

This class defines the __setattr__(), __getattr__() and __delattr__() methods, and they set, get and delete ordinary Python attributes as normally intended. In addition to that, __getattr__() allows getting child nodes by their name for the sake of easy interaction on the command line, as long as there is no Python attribute with the same name. Groups also allow the interactive completion (when using readline) of the names of child nodes. For instance:

# get a Python attribute
nchild = group._v_nchildren

# Add a Table child called 'table' under 'group'.
h5file.createTable(group, 'table', myDescription)
table = group.table          # get the table child instance
group.table = 'foo'          # set a Python attribute

# (PyTables warns you here about using the name of a child node.)
foo = group.table            # get a Python attribute
del group.table              # delete a Python attribute
table = group.table          # get the table child instance again

The Leaf class

Leaf properties

Leaf.size_in_memory

The size of this leaf’s data in bytes when it is fully loaded into memory.

Leaf instance variables - aliases

The following are just easier-to-write aliases to their Node (see The Node class) counterparts (indicated between parentheses):

Leaf methods

The Table class

Table properties

Table methods - reading

Table methods - writing

Table methods - querying

Table methods - other

The Description class

Description methods

The Row class

Row methods

Row special methods

The Cols class

Cols properties

Cols methods

The Column class

Column instance variables

Column methods

Column special methods

The Array class

Array instance variables

Array.atom

An Atom (see The Atom class and its descendants) instance representing the type and shape of the atomic objects to be saved.

Array.nrow

On iterators, this is the index of the current row.

Array methods

Array special methods

The following methods automatically trigger actions when an Array instance is accessed in a special way (e.g. array[2:3,...,::2] will be equivalent to a call to array.__getitem__((slice(2, 3, None), Ellipsis, slice(None, None, 2)))).

The CArray class

The EArray class

EArray methods

The VLArray class

VLArray properties

VLArray methods

VLArray special methods

The following methods automatically trigger actions when a VLArray instance is accessed in a special way (e.g., vlarray[2:5] will be equivalent to a call to vlarray.__getitem__(slice(2, 5, None)).

The UnImplemented class

The Unknown class

The AttributeSet class

AttributeSet properties

AttributeSet methods

Declarative classes

In this section a series of classes that are meant to declare datatypes that are required for creating primary PyTables datasets are described.

The Atom class and its descendants

Atom properties

Atom methods

Atom factory methods

Atom Sub-classes

Pseudo atoms

Now, there come three special classes, ObjectAtom, VLStringAtom and VLUnicodeAtom, that actually do not descend from Atom, but which goal is so similar that they should be described here. Pseudo-atoms can only be used with VLArray datasets (see The VLArray class), and they do not support multidimensional values, nor multiple values per row.

They can be recognised because they also have kind, type and shape attributes, but no size, itemsize or dflt ones. Instead, they have a base atom which defines the elements used for storage.

See examples/vlarray1.py and examples/vlarray2.py for further examples on VLArray datasets, including object serialization and string management.

ObjectAtom
VLStringAtom
VLUnicodeAtom

The Col class and its descendants

Col instance variables

In addition to the variables that they inherit from the Atom class, Col instances have the following attributes.

Col._v_pos

The relative position of this column with regard to its column siblings.

Col factory methods

Col sub-classes

The IsDescription class

Description helper functions

Helper classes

This section describes some classes that do not fit in any other section and that mainly serve for ancillary purposes.

The Filters class

Filters methods

The Index class

Index instance variables

tables.index.Index.nelements

The number of currently indexed rows for this column.

Index methods

Index special methods

The IndexArray class

The Enum class

Enum special methods

The Expr class - a general-purpose expression evaluator

Expr methods

Expr special methods

Exceptions module

In the exceptions module exceptions and warnings that are specific to PyTables are declared.

Table Of Contents

Previous topic

Tutorials

Next topic

Optimization tips

This Page