DelfiniItem¶
- class pydelfini.collections.DelfiniItem(collection, in_folder, model, core)[source]¶
Bases:
objectRepresents an item within a collection.
Attributes
Item column definitions
Datetime item was created
Item internal ID
Datetime item was last modified
Item metadata
Item name
Item parser settings
Item fully qualified path
Item type (
file,folder,dataview, etc.)Collection that contains this item
Folder that contains this item
- Parameters:
collection (DelfiniCollection)
in_folder (FolderMixin)
model (Item)
core (AuthenticatedClient)
- Return type:
- collection: DelfiniCollection¶
Collection that contains this item
- property columns: list[ItemColumn] | None¶
Item column definitions
- in_folder: FolderMixin¶
Folder that contains this item
- 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 moderb- reading, binary modew- writing, text modewb- writing, binary mode
parser – If writing, optionally specify the item parser type. Typical values for this would be
csvorparquet.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
parserto be set.
- Returns:
A file-like interface, either
BinaryIOorTextIOdepending on whether the file was to be opened in binary or text mode. When writing, the return will be an instance ofitem_io.DelfiniItemWriterBinaryoritem_io.DelfiniItemWriterText.
- overwrite_table_data(dataframe, format='csv', **kwargs)[source]¶
Write a
pd.DataFrameto this item, overwriting existing data.- Parameters:
dataframe (DataFrame) – The dataframe to be written.
format (Literal['csv', 'parquet']) – One of the supported formats (
csvorparquet).**kwargs (Any) – Any other arguments to be passed to the Pandas export function. See the documentation for
pd.DataFrame.to_csv()orpd.DataFrame.to_parquet()for valid arguments.
- Return type:
None
- property parser: ItemParser | None¶
Item parser settings
- set_parser(parser, columns=None)[source]¶
Update the item’s parser and optionally columns.
- Parameters:
parser (str | ItemParser) – Parser name (str) or ItemParser object.
columns (None | Series | Schema | list[ItemColumn]) – Optional column schema.
- Return type:
None