Skip to content

Read

pykx.read

QReader

QReader(q)

Read data using q.

csv

csv(path, types=None, delimiter=',', as_table=True)

Reads a CSV file as a table or dictionary.

Column types are guessed if not provided.

Parameters:

Name Type Description Default
path Union[str, Path, k.SymbolAtom]

The path to the CSV file.

required
types Optional[Union[bytes, k.CharAtom, k.CharVector]]

A str-like object of uppercase characters representing the types. Space is used to drop a column. If None, the types will be guessed using .csvutil.info.

None
delimiter Union[str, bytes, k.CharAtom]

A single character representing the delimiter between values.

','
as_table Union[bool, k.BooleanAtom]

True if the first line of the CSV file should be treated as column names, in which case a pykx.Table is returned. If False a pykx.List of pykx.Vector is returned - one for each column in the CSV file.

True

Returns:

Type Description
Union[k.Table, k.Dictionary]

The CSV data as a pykx.Table or pykx.List, depending on the value of as_table.

See Also

q.write.csv

Examples:

Read a comma seperated CSV file into a pykx.Table guessing the datatypes of each column.

table = q.read.csv('example.csv')

Read a tab seperated CSV file into a pykx.Table while specifying the columns datatypes to be a pykx.SymbolVector followed by two pykx.LongVector columns.

table = q.read.csv('example.csv', 'SJJ', '      ')

Read a comma seperated CSV file into a pykx.Dictionary, guessing the datatypes of each column.

table = q.read.csv('example.csv', None, None, False)

splayed

splayed(root, name)

Loads a splayed table.

Parameters:

Name Type Description Default
root Union[str, Path, k.SymbolAtom]

The path to the root directory of the splayed table.

required
name Union[str, k.SymbolAtom]

The name of the table to read.

required

Returns:

Type Description
k.SplayedTable

The splayed table as a pykx.SplayedTable.

See Also

q.write.splayed

Examples:

Reads a splayed table named t found within the current directory

table = q.read.splayed('.', 't')

Reads a splayed table named splayed found within the /tmp directory

table = q.read.splayed('/tmp', 'splayed')

fixed

fixed(path, types, widths)

Loads a file of typed data with fixed-width fields.

It is expected that there will either be a newline after every record, or none at all.

Parameters:

Name Type Description Default
path Union[str, Path, k.SymbolAtom]

The path to the file containing the fixed-width field data.

required
types Union[bytes, k.CharVector]

A string of uppercase characters representing the types. Space is used to drop a column.

required
widths Union[List[int], k.LongVector]

The width in bytes of each field.

required

Returns:

Type Description
k.List

The data as a pykx.List with a pykx.Vector for each column.

Examples:

Read a file of fixed width data into a pykx.List of two pykx.LongVectors the first with a size of 1 character and the second with a size of 2 characters.

data = q.read.fixed('example_file', [b'J', b'J'], [1, 2])

json

json(path)

Reads a JSON file into a k.Table.

Parameters:

Name Type Description Default
path Union[str, Path, k.SymbolAtom]

The path to the JSON file.

required

Returns:

Type Description
JSONKTypes

The JSON data as a pykx.K object.

See Also

q.write.json

Examples:

Read a JSON file.

data = q.read.json('example.json')

serialized

serialized(path)

Reads a binary file containing serialized q data.

Parameters:

Name Type Description Default
path Union[str, Path, k.SymbolAtom]

The path to the q data file.

required

Returns:

Type Description
k.K

The q data file converted to a pykx object.

See Also

q.write.serialized

Examples:

Read a q data file containing a serialized table into a pykx.Table object.

table = q.read.serialized('q_table_file')