DelfiniItem

class pydelfini.collections.DelfiniItem(collection, in_folder, model, core)[source]

Bases: object

Represents an item within a collection.

Attributes

columns

Item column definitions

created_on

Datetime item was created

id

Item internal ID

last_modified

Datetime item was last modified

metadata

Item metadata

name

Item name

parser

Item parser settings

path

Item fully qualified path

type

Item type (file, folder, dataview, etc.)

collection

Collection that contains this item

in_folder

Folder that contains this item

Parameters:
Return type:

DelfiniItem

collection: DelfiniCollection

Collection that contains this item

property columns: list[ItemColumn] | None

Item column definitions

property created_on: datetime

Datetime item was created

property id: str

Item internal ID

in_folder: FolderMixin

Folder that contains this item

property last_modified: datetime

Datetime item was last modified

property metadata: dict[str, str]

Item metadata

property name: str

Item name

open(mode: Literal['rb'], *, parser: None | str | ItemParser = None, metadata: dict[str, str] | None = None, columns: None | Series | Schema | list[ItemColumn] = None) BinaryIO[source]
open(mode: Literal['r'], *, parser: None | str | ItemParser = None, metadata: dict[str, str] | None = None, columns: None | Series | Schema | list[ItemColumn] = None) TextIO
open(mode: Literal['wb'], *, parser: None | str | ItemParser = None, metadata: dict[str, str] | None = None, columns: None | Series | Schema | list[ItemColumn] = None) BinaryIO
open(mode: Literal['w'], *, parser: None | str | ItemParser = None, metadata: dict[str, str] | None = None, columns: None | Series | Schema | list[ItemColumn] = None) TextIO

Open this item for reading or writing.

When writing an item, it is important to use the returned file-like object either in a context manager or else call its close() method when writing is complete, otherwise the full contents of the file may not be written.

Suggested usage:

with item.open('wb') as fp:
    fp.write(b'my item content, as much as I have\n')
Parameters:
  • mode

    One of the following values, depending on the desired interaction mode:

    • r - reading, text mode

    • rb - reading, binary mode

    • w - writing, text mode

    • wb - writing, binary mode

  • parser – If writing, optionally specify the item parser type. Typical values for this would be csv or parquet.

  • metadata – If writing, optionally specify the item metadata. Typical values for this would be something like {"content-type": "text-csv"}.

  • columns – If writing, optionally specify the item column schema. Requires parser to be set.

Returns:

A file-like interface, either BinaryIO or TextIO depending on whether the file was to be opened in binary or text mode. When writing, the return will be an instance of item_io.DelfiniItemWriterBinary or item_io.DelfiniItemWriterText.

overwrite_table_data(dataframe, format='csv', **kwargs)[source]

Write a pd.DataFrame to this item, overwriting existing data.

Parameters:
  • dataframe (DataFrame) – The dataframe to be written.

  • format (Literal['csv', 'parquet']) – One of the supported formats (csv or parquet).

  • **kwargs (Any) – Any other arguments to be passed to the Pandas export function. See the documentation for pd.DataFrame.to_csv() or pd.DataFrame.to_parquet() for valid arguments.

Return type:

None

property parser: ItemParser | None

Item parser settings

property path: str

Item fully qualified path

set_metadata(new_metadata)[source]

Update the item’s metadata.

Parameters:

new_metadata (dict[str, str]) – Dictionary of metadata key-value pairs to set.

Return type:

None

set_parser(parser, columns=None)[source]

Update the item’s parser and optionally columns.

Parameters:
Return type:

None

table()[source]

Retrieve the tabular contents of this item as a pd.DataFrame.

Return type:

DataFrame

property type: ItemType

Item type (file, folder, dataview, etc.)