Project#

class skore.Project(path='project.skore', *, if_exists='raise')[source]#

A collection of items persisted in a storage.

Its main methods are put() and get(), respectively to insert a key-value pair into the Project and to recover the value associated with a key.

You can add any type of objects. In some cases, especially on classes you defined, the persistency is based on the pickle representation. You must therefore ensure that the call to get() is made in the same environment as put().

Parameters:
pathstr or Path, optional

The path of the project to initialize, default “./project.skore”.

if_exists: Literal[“raise”, “load”], optional

Raise an exception if the project already exists, or load it, default raise.

Attributes:
pathPath

The unified path of the project.

namestr

The name of the project. Corresponds to path.name.

Examples

>>> import skore
>>> project = skore.Project("my-xp")  
>>> project.put("score", 1.0)  
>>> project.get("score")  
1.0
clear(delete_project=False)[source]#

Remove all items from the project.

Warning

Clearing the project with delete_project=True will invalidate the whole Project instance, making it unusable. A new Project instance can be created using the skore.Project constructor or the skore.open() function.

Parameters:
delete_projectbool

If set, the project will be deleted entirely.

delete(key)[source]#

Delete the item corresponding to key from the Project.

Parameters:
keystr

The key corresponding to the item to delete.

Raises:
KeyError

If the key does not correspond to any item.

delete_note(key, *, version=-1)[source]#

Delete a note previously attached to key key.

If no note is attached, does nothing.

Parameters:
keystr

The key of the annotated item. May be qualified with a version number through the version argument.

versionint, default=-1

The version of the annotated key. Default is the latest version.

Raises:
KeyError

If the (key, version) couple does not exist.

Examples

>>> # Delete note attached to latest version of key "key"
>>> project.delete_note("key")  
>>> # Delete note attached to first version of key "key"
>>> project.delete_note("key", version=0)  
get(key, *, version=-1, metadata=False)[source]#

Get the value associated to key from the Project.

Parameters:
keystr

The key corresponding to the item to get.

versionUnion[Literal[-1, “all”], int], default=-1

If -1, get the latest value associated to key. If “all”, get all the values associated to key. If instance of int, get the nth value associated to key.

metadatabool, default=False

If True, get the metadata in addition to the value.

Returns:
valueany

Value associated to key, when latest=True and metadata=False.

value_and_metadatadict

Value associated to key with its metadata, when latest=True and metadata=True.

list_of_valueslist[any]

Values associated to key, ordered by date, when latest=False.

list_of_values_and_metadatalist[dict]

Values associated to key with their metadata, ordered by date, when latest=False and metadata=False.

Raises:
KeyError

If the key is not in the project.

get_note(key, *, version=-1)[source]#

Retrieve a note previously attached to key key.

Parameters:
keystr

The key of the annotated item. May be qualified with a version number through the version argument.

versionint, default=-1

The version of the annotated key. Default is the latest version.

Returns:
The attached note, or None if no note is attached.
Raises:
KeyError

If the (key, version) couple does not exist.

Examples

>>> # Retrieve note attached to latest version of key "key"
>>> project.get_note("key")  
>>> # Retrieve note attached to first version of key "key"
>>> project.get_note("key", version=0)  
keys()[source]#

Get all keys of items stored in the project.

Returns:
list[str]

A list of all keys.

put(key, value, *, note=None, display_as=None)[source]#

Add a key-value pair to the Project.

If an item with the same key already exists, its value is replaced by the new one.

Parameters:
keystr

The key to associate with value in the Project.

valueAny

The value to associate with key in the Project.

notestr, optional

A note to attach with the item.

display_as{“HTML”, “MARKDOWN”, “SVG”}, optional

Used in combination with a string value, it customizes the way the value is displayed in the interface.

Raises:
TypeError

If the combination of parameters are not valid.

NotImplementedError

If the value type is not supported.

set_note(key, note, *, version=-1)[source]#

Attach a note to key key.

Parameters:
keystr

The key of the item to annotate. May be qualified with a version number through the version argument.

notestr

The note to be attached.

versionint, default=-1

The version of the key to annotate. Default is the latest version.

Raises:
KeyError

If the (key, version) couple does not exist.

TypeError

If key or note is not a string.

Examples

>>> # Annotate latest version of key "key"
>>> project.set_note("key", "note")  
>>> # Annotate first version of key "key"
>>> project.set_note("key", "note", version=0)  
shutdown_web_ui()[source]#

Shutdown the web UI server if it is running.