Pieces OS Client Python SDK Assets
Use the following methods to manage your assets with the Pieces OS Client Python SDK.
Asset Management
Create a New Asset
The create_asset()
method requires the content of the asset and optional metadata. The method returns the ID of the created asset.
create_asset(content, metadata)
Parameters
Name | Type | Notes |
---|---|---|
content | string | [required] |
metadata | FragmentMetadata | [optional] |
Example
from pieces_os_client.wrapper import PiecesClient
from pieces_os_client import ClassificationSpecificEnum, FragmentMetadata
# Initialize the PiecesClient
pieces_client = PiecesClient()
# Set the content and metadata for the new asset
content = "print('Hello, World!')"
metadata = FragmentMetadata(ext=ClassificationSpecificEnum.PY) # optional metadata
# Create the new asset using the content and metadata
new_asset_id = pieces_client.create_asset(content, metadata)
print(f"Created asset with ID: {new_asset_id}")
# Close the client
pieces_client.close()
Get a Specific Asset
The asset()
method requires the asset ID and returns the asset as a BasicAsset object.
asset(asset_id)
Parameters
Name | Type | Notes |
---|---|---|
asset_id | string | [required] |
Example
from pieces_os_client.wrapper import PiecesClient
# Initialize the PiecesClient
pieces_client = PiecesClient()
# Get the asset ID
asset_id = "your_asset_id"
# Retrieve the asset
asset = pieces_client.asset(asset_id)
# Close the client
pieces_client.close()
Get All Assets
The assets()
method returns a list of all assets with id
and name
properties.
assets()
Example
from pieces_os_client.wrapper import PiecesClient
# Initialize the PiecesClient
pieces_client = PiecesClient()
# Get all assets and print their names
assets = pieces_client.assets()
for asset in assets:
print(f"Asset Name: {asset.name}")
# Close the client
pieces_client.close()
BasicAsset Class
The BasicAsset
class provides a way to manage assets with various properties and methods.
Properties
Name | Type | Notes |
---|---|---|
id | string | The ID of the asset. |
asset | Asset | Should only be used for properties not available in the BasicAsset class. |
raw_content | string | The content of the asset. |
is_image | bool | Boolean indicating if the asset is an image. |
classification | ClassificationSpecificEnum | The specific language classification of the asset. To get the string value, you must use asset.classification.value |
name | string | The name of the asset. |
description | string | The description of the asset. |
annotations | Annotations | The annotations of the asset. |