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 7 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.…
choir27 Aug 15, 2024
1c27281
add note info to include Pieces OS for SDk. Update location to href r…
choir27 Aug 17, 2024
7bf757b
Merge branch 'main' into python-sdk
choir27 Aug 17, 2024
12ce3f2
add sdk sidebar wrapper navigation
choir27 Aug 22, 2024
de652ea
organize python sdk in sidebar. add methods, properties, and class me…
choir27 Aug 23, 2024
a69d7f5
clean up formatting
choir27 Aug 23, 2024
2579ab9
update code samples to be more consistent and fix any small mistakes …
choir27 Aug 23, 2024
f8f3e0a
clean up docs
choir27 Aug 23, 2024
a6c405d
replace baseURL with host
choir27 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
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
222 changes: 222 additions & 0 deletions docs/build/sdks/python/assets/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
---
title: Pieces Wrapper Python SDK Assets
description: Learn how to set up and use the Pieces Wrapper Python SDK Asset methods
---

# Pieces wrapper python SDK asset methods

## create_asset()

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

Creates a new asset.

### Parameters

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

### Example

```python
from pieces_os_client.wrapper import PiecesClient
from pieces_os_client import FragmentMetadata

# Replace 'your_base_url' with the base URL of your Pieces OS server
pieces_client = PiecesClient(config={'baseUrl': 'your_base_url'})
shivay-at-pieces marked this conversation as resolved.
Show resolved Hide resolved

# 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}")
```

## assets()

```python
assets()
```

Gets all your assets.

### Example

```python
from pieces_os_client.wrapper import PiecesClient

# Replace 'your_base_url' with the base URL of your Pieces OS server
pieces_client = PiecesClient(config={'baseUrl': 'your_base_url'})

# Get all assets and print their names
assets = pieces_client.assets()
for asset in assets:
logger.info(f"Asset Name: {asset.name}")
```

## BasicAsset

The `BasicAsset` class provides a way to manage assets with various properties and methods.

```python
BasicAsset(id)
```

### Parameters

| Name | Description | Type | Notes |
|------------- | ------------ | -------------| -------------|
| **id** | Your asset id. Raises: ValueError if the provided ID is invalid. | **string** | [required] |

### Properties

#### id
Returns the asset ID.

#### raw_content
Edit the original format of the asset.

##### Arguments:

| Name | Description |
| ------------- | ------------ |
| **data** | The new data to be set. |

##### Raises:

| Name | Description |
| ------------- | ------------ |
| **NotImplementedError** | If the asset is an image.|

#### is_image
Check if the asset is an image.

##### On return

| Type | Description |
| ------------- | ------------ |
| **bool** | `True` if the asset is an image, otherwise `False`. |

#### classification
Get the specific classification of the asset (e.g., py).

##### On return

| Type | Description |
| ------------- | ------------ |
| **classification value**/**None** | The classification value of the asset, or `None` if not available. |

#### classification setter
Reclassify an asset

#### name setter
Edit the name of the asset.

- `name`: The new name to be set for the asset.

#### description
Retrieve the description of the asset.

##### On return

| Type | Description |
| ------------- | ------------ |
| **string/None** | The description text of the asset, or `None` if not available. |

#### annotations
Get all annotations of the asset.

| Type | Description |
| ------------- | ------------ |
|**Optional[Annotations]/None** |The annotations if available, otherwise `None`.|

### Methods

#### `delete()`
Delete the asset.

#### `create()`
Create a new asset.

##### Arguments

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

##### Returns

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

### Example

```python
from pieces_copilot_sdk import PiecesClient
from pieces_copilot_sdk.basic_identifier import BasicAsset
from pieces_os_client import ClassificationSpecificEnum

# Replace 'your_base_url' with your actual base URL
pieces_client = PiecesClient(config={'baseUrl': 'your_base_url'})

asset = pieces_client.assets()[0]

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

# 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()
```

## Community
If you have created your own SDK or any other technology specific integration and would like us to list it here under community maintained SDKs/integrations please [contact us](https://github.com/pieces-app/opensource/discussions).

If you would like to help us expand Pieces' list of SDKs, you can start a new discussion on our [Open Source Discussions](https://github.com/pieces-app/opensource/discussions) and you can also join our [Discord](https://discord.gg/getpieces).
Loading