Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python sdk #547

Merged
merged 20 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
189589b
docs: add Pieces Python SDK to sidebar nav. Add installation section.…
choir241 Aug 15, 2024
1c27281
add note info to include Pieces OS for SDk. Update location to href r…
choir241 Aug 17, 2024
7bf757b
Merge branch 'main' into python-sdk
choir241 Aug 17, 2024
12ce3f2
add sdk sidebar wrapper navigation
choir241 Aug 22, 2024
de652ea
organize python sdk in sidebar. add methods, properties, and class me…
choir241 Aug 23, 2024
a69d7f5
clean up formatting
choir241 Aug 23, 2024
2579ab9
update code samples to be more consistent and fix any small mistakes …
choir241 Aug 23, 2024
f8f3e0a
clean up docs
choir241 Aug 23, 2024
a6c405d
replace baseURL with host
choir241 Aug 23, 2024
01fb7a7
docs(refactor): update SDK docs for Python integration
mason-at-pieces Aug 23, 2024
36f4cfa
style: Correct capitalization of TypeScript
mason-at-pieces Aug 23, 2024
7f33ba2
docs: update Python SDK documentation and examples
mason-at-pieces Aug 23, 2024
ae33595
docs: Update Python SDK Copilot documentation
mason-at-pieces Aug 24, 2024
13d4734
docs: Fix Conversation link capitalization
mason-at-pieces Aug 24, 2024
a8f9649
docs: Update Python SDK copilot usage example
mason-at-pieces Aug 24, 2024
5cea1c6
docs: Add return types to asset properties table
mason-at-pieces Aug 24, 2024
028ea33
docs: standardize table headers in Python SDK docs
mason-at-pieces Aug 24, 2024
3f69c3e
docs: Update parameter table in Python SDK docs
mason-at-pieces Aug 24, 2024
5a38a88
docs: Update Pieces Client host URL setup guide
mason-at-pieces Aug 24, 2024
1ba91a7
docs: Add client closing instructions to Python SDK
mason-at-pieces Aug 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/build/examples/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ import CTAButton from "/src/components/CTAButton";
import {GithubIcon} from "/src/components/Icons";
import {MiniSpacer} from "/src/components/Spacers";

Explore projects that use the Pieces SDK in various frameworks.

:::info

These projects are community-contributed and may not be maintained by the Pieces team.

These projects may not using our latest [SDKs](/build/sdks/python). We recommend using the built-in wrapper SDKs for an improved developer experience.

:::

## Examples

<Grid cols={2}>
<div className={'grid-card'}>
<div style={{
Expand Down
51 changes: 2 additions & 49 deletions docs/build/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,58 +58,11 @@ We're always working on improving and extending the current stack of available S
<p>Python SDK for Pieces OS</p>
<CTAButton
label={'Get Started'}
href={'/build/reference/python'}
type={'secondary'}
/>
</div>
<div className={'grid-card'}>
<div style={{
display: 'flex',
alignItems: 'center',
gap: '10px'
}}>
<img
src={'/assets/languages/dart_logo.png'}
alt={'Dart Logo'}
width={40}
/>
<span style={{
fontSize: '1.5rem',
fontWeight: 'bold'
}}>Dart SDK</span>
</div>
<MiniSpacer/>
<p>Dart SDK for Pieces OS</p>
<CTAButton
label={'Get Started'}
href={'/build/reference/dart'}
type={'secondary'}
/>
</div>
<div className={'grid-card'}>
<div style={{
display: 'flex',
alignItems: 'center',
gap: '10px'
}}>
<img
src={'/assets/languages/kotlin_logo.png'}
alt={'Kotlin Logo'}
width={40}
/>
<span style={{
fontSize: '1.5rem',
fontWeight: 'bold'
}}>Kotlin SDK</span>
</div>
<MiniSpacer/>
<p>Kotlin SDK for Pieces OS</p>
<CTAButton
label={'Get Started'}
href={'reference/kotlin'}
href={'/build/sdks/python'}
type={'secondary'}
/>
</div>

</Grid>

<MiniSpacer />
Expand Down
303 changes: 303 additions & 0 deletions docs/build/sdks/python/assets.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
---
title: Pieces OS Client Python SDK Assets
description: Learn how to set up and use the Pieces OS Client Python SDK to manage 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.

```python
create_asset(content, metadata)
```

#### Parameters

| Param Name | Param Type | Param Notes |
|------------- |------------ |-------------|
| **content** | **string** | [required] |
| **metadata** | **FragmentMetadata** | [optional] |

#### Example

```python
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](#basicasset-class) object.

```python
asset(asset_id)
```

#### Parameters

| Param Name | Param Type | Param Notes |
|------------- |------------ |-------------|
| **asset_id** | **string** | [required] |

#### Example

```python
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.

```python
assets()
```

#### Example

```python
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

| Property Name | Property Description | Return Type |
|--------------- |---------------------- |------------|
| **id** | The ID of the asset. | **string** |
| **asset** | Should **only** be used for properties not available in the `BasicAsset` class. | [**Asset**](/build/reference/python/models/Asset) |
| **raw_content** | The content of the asset. | **string** |
| **is_image** | Boolean indicating if the asset is an image. | **bool** |
| **classification** | The specific classification of the asset (e.g., `py`). | [**ClassificationSpecificEnum**](/build/reference/python/models/ClassificationSpecificEnum) |
| **name** | The name of the asset. | **string** |
| **description** | The description of the asset. | **string** |
| **annotations** | The annotations of the asset. | [**Annotations**](/build/reference/python/models/Annotations) |

### Methods

#### `create()`

Creates a new asset.

##### Parameters

| Param Name | Param Type | Param Description |
|------------ |------------|------------------|
| **raw_content** | **string** | The raw content of the asset. |
| **metadata** | **Optional[FragmentMetadata]** | The metadata of the asset. |

##### Returns

| Return Type | Return Description |
|------------- |-------------------|
| **string** | The ID of the created asset. |

##### Example

```python
from pieces_os_client.wrapper import PiecesClient
from pieces_os_client.wrapper.basic_identifier.asset import BasicAsset
from pieces_os_client import ClassificationSpecificEnum, FragmentMetadata

# Initialize the PiecesClient
pieces_client = PiecesClient()

# Create a new asset
content = "print('Hello, World!')"
metadata = FragmentMetadata(ext=ClassificationSpecificEnum.PY)
new_asset_id = BasicAsset.create(content, metadata)
print(f"New Asset ID: {new_asset_id}")

# Close the client
pieces_client.close()
```

#### `delete()`

Deletes the asset.

##### Example

```python
# Retrieve the asset
asset = pieces_client.asset(asset_id)

# Delete the asset
asset.delete()

# Close the client
pieces_client.close()
```

#### `raw_content`

Updates the raw content of the asset.

##### Example

```python
# Retrieve the asset
asset = pieces_client.asset(new_asset_id)

# Get the asset content
content = asset.raw_content
print(f"Original Content: {content}")

# Update the content
asset.raw_content = content + "\n# This is a comment"
print(f"Updated Content: {asset.raw_content}")

# Close the client
pieces_client.close()
```

#### `classification`

Updates the classification of the asset.

##### Example

```python
# Retrieve the asset
asset = pieces_client.asset(new_asset_id)

# Get the asset classification
classification = asset.classification.value if asset.classification else "None"
print(f"Asset Classification: {classification}")

# Update the classification
asset.classification = ClassificationSpecificEnum.SH # Reclassify to shell
print(f"New Classification: {classification}")

# Close the client
pieces_client.close()
```

#### `name`

Updates the name of the asset.

##### Example

```python
# Retrieve the asset
asset = pieces_client.asset(new_asset_id)

# Get the asset name
print(f"Current Asset Name: {asset.name}")

# Update the name
asset.name = "Updated Asset Name"
print(f"Updated Asset Name: {asset.name}")

# Close the client
pieces_client.close()
```

### Full Example

```python
from pieces_os_client.wrapper import PiecesClient
from pieces_os_client.basic_asset import BasicAsset
from pieces_os_client import ClassificationSpecificEnum

# Initialize the PiecesClient
pieces_client = PiecesClient()

asset = pieces_client.assets()[0]

# Get the asset ID
asset_id = asset.id
print(f"Asset ID: {asset_id}")

# Get the full asset object (only for properties not available in BasicAsset)
full_asset = asset.asset
print(f"Full Asset Object: {full_asset}")

# Check if the asset is an image
if asset.is_image:
print("The asset is an image.")
else:
print("The asset is not an image.")

# Get and set the asset name
print(f"Current Asset Name: {asset.name}")
asset.name = "Updated Asset Name"
print(f"Updated Asset Name: {asset.name}")

# Retrieve and modify the asset content
content = asset.raw_content
print(f"Original Content: {content}")
asset.raw_content = content + "\n# This is a comment"
print(f"Updated Content: {asset.raw_content}")

# Get the asset classification
classification = asset.classification.value if asset.classification else "None"
print(f"Asset Classification: {classification}")

asset.classification = ClassificationSpecificEnum.SH # Reclassify to shell
print(f"New Classification: {classification}")

# Get the asset description
description = asset.description if asset.description else "No description available."
print(f"Asset Description: {description}")

# Get the asset annotations
annotations = asset.annotations if asset.annotations else "No annotations available."
print(f"Asset Annotations: {annotations}")

# Delete the asset
asset.delete()
print("Asset deleted.")

# Create a new asset
new_asset_id = BasicAsset.create("New Asset content")
print(f"New Asset ID: {new_asset_id}")

pieces_client.close()
```
Loading