DelfiniCollection¶
- class pydelfini.collections.DelfiniCollection(model, core)[source]¶
Bases:
FolderMixin
Represents a collection on a Delfini instance.
Typically created by one of the collection methods in
pydelfini.client.DelfiniClient
.In addition to collection-specific attributes and methods, this class also behaves as a folder (representing the top level of the collection’s folder structure). See
FolderMixin
for those methods.Attributes
Datetime when collection was created
Collection text description
Collection internal ID
Collection metadata
Collection name
path
Current version ID
- Parameters:
model (Collection)
core (AuthenticatedClient)
- __getitem__(item_path)¶
Retrieve an item in this folder.
Relative paths are supported, such as
folder_a/folder_b/item_c
.- Parameters:
item_path (str)
- Return type:
- __iter__()¶
Iterate over all items in this folder.
- Return type:
- delete_collection()[source]¶
Deletes the entire collection, permanently.
You cannot delete the LIVE version of a collection if there exist other versions of the collection.
- Return type:
None
- folder(folder_name)¶
Open the named folder.
- Parameters:
folder_name (str) – the name of the folder to open
- Return type:
- get_item_by_id(item_id)[source]¶
Retrieves an item by its unique ID.
- Parameters:
item_id (str)
- Return type:
- get_table(item_path)¶
Retrieve the tabular contents of an item as a
pd.DataFrame
.
- new_empty_file(file_name)¶
Create a new, empty file.
- Parameters:
file_name (str) – the name of the file to create
- Return type:
- new_folder(folder_name)¶
Create a new folder.
- Parameters:
folder_name (str) – the name of the folder to create
- Return type:
- new_link(target, link_name=None)¶
Create a new link pointing to a target.
- Parameters:
- Return type:
- open(item_path: str, mode: Literal['r']) TextIO [source]¶
- open(item_path: str, mode: Literal['rb']) BinaryIO
- open(item_path: str, mode: Literal['w'], *, type: Literal['file', 'dataview', 'dictionary'] = 'file', parser: None | str | ItemParser = None, columns: None | Series | Schema | list[ItemColumn] = None, metadata: dict[str, str] | None = None) TextIO
- open(item_path: str, mode: Literal['wb'], *, type: Literal['file', 'dataview', 'dictionary'] = 'file', parser: None | str | ItemParser = None, columns: None | Series | Schema | list[ItemColumn] = None, metadata: dict[str, str] | None = None) BinaryIO
Open an 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 collection.open('new-item', 'wb') as fp: fp.write(b'my item content, as much as I have\n')
- Parameters:
item_path – The path to the item relative to the top level of the collection. Accepts slashes (‘/’) for items located in subfolders.
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
csv
orparquet
.columns – If writing, optionally specify the item column schema. Requires
parser
to be set.metadata – If writing, optionally specify the item metadata. Typical values for this would be something like
{"content-type": "text-csv"}
.
- Returns:
A file-like interface, either
BinaryIO
orTextIO
depending on whether the file was to be opened in binary or text mode. When writing, the return will be an instance ofitem_io.DelfiniItemCreatorBinary
oritem_io.DelfiniItemCreatorText
.
- walk()¶
Iterate over all items in this folder, and all subfolders.
- Return type:
- write_table(item_path, dataframe, format='csv', **kwargs)¶
Write a
pd.DataFrame
to the named item.- Parameters:
item_path (str) – The path to the item relative to the current folder. Accepts slashes (‘/’) for items in subfolders.
dataframe (DataFrame) – The dataframe to be written.
format (Literal['csv', 'parquet']) – One of the supported formats (
csv
orparquet
).**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