Name | pieces_os_client JSON |
Version |
4.0.4
JSON |
| download |
home_page | https://pieces.app |
Summary | A powerful code engine package for writing applications on top of Pieces OS |
upload_time | 2024-11-15 12:18:44 |
maintainer | None |
docs_url | None |
author | Pieces |
requires_python | <4.0,>=3.8 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<h1 align="center">
<b>
<a href="https://pieces.app">
<picture>
<source srcset="https://github.com/user-attachments/assets/6d1c9fc1-11d5-47b0-bb39-a81d40d8fab0" media="(prefers-color-scheme: light)">
<source srcset="https://github.com/user-attachments/assets/4529e56f-f614-4743-8ca8-33e0c040b069" media="(prefers-color-scheme: dark)">
<img src="https://github.com/user-attachments/assets/4529e56f-f614-4743-8ca8-33e0c040b069" height="125" width="600" />
</picture>
</a><br>
</b>
</h1>
# <p align="center"> Pieces OS Client SDK For Python
<p align="center">
<a href="https://github.com/pieces-app/pieces-os-client-sdk-for-python/graphs/contributors" alt="GitHub contributors">
<img src="https://img.shields.io/github/contributors/pieces-app/pieces-os-client-sdk-for-python.svg" />
</a>
<a href="https://github.com/pieces-app/pieces-os-client-sdk-for-python/issues" alt="GitHub issues by-label">
<img src="https://img.shields.io/github/issues/pieces-app/pieces-os-client-sdk-for-python" />
</a>
<a href="https://discord.gg/getpieces" alt="Discord">
<img src="https://img.shields.io/badge/Discord-@layer5.svg?color=7389D8&label&logo=discord&logoColor=ffffff" />
</a>
<a href="https://twitter.com/getpieces" alt="Twitter Follow">
<img src="https://img.shields.io/twitter/follow/pieces.svg?label=Follow" />
</a>
<a href="https://github.com/pieces-app/pieces-os-client-sdk-for-python/blob/main/LICENSE" alt="License">
<img src="https://img.shields.io/github/license/pieces-app/pieces-os-client-sdk-for-python.svg" />
</a>
<a href="https://pypi.org/project/pieces_os_client" >
<img src="https://badge.fury.io/py/pieces-os-client.svg" />
</a>
<a href="https://pepy.tech/project/pieces_os_client" >
<img src="https://static.pepy.tech/badge/pieces_os_client" />
</a>
</p>
</p>
## Introduction
The Pieces OS Client SDK is a powerful code engine package designed for writing applications on top of Pieces OS. It facilitates communication with a locally hosted server to enable features such as copilot chats, asset saving, and more.
## Features
The Pieces SDK offers the following key features:
1. Copilot Chats: Communicate seamlessly with copilot chats functionality.
2. Asset Management: Save and manage assets and formats efficiently.
3. Local Server Interaction: Interact with a locally hosted server for various functionalities.
4. Multi LLMs support: Use any Pieces supported LLM to power your app.
## Installation
To get started with the Pieces OS Client SDK, follow these steps:
1. **Download Pieces OS**: Pieces OS serves as the primary backend service, providing essential functionality for the SDK. Download the appropriate version for your operating system:
- [macOS](https://docs.pieces.app/installation-getting-started/macos)
- [Windows](https://docs.pieces.app/installation-getting-started/windows)
- [Linux](https://docs.pieces.app/installation-getting-started/linux)
2. **Install the SDK**: Use pip to install the Pieces OS Client SDK package:
```shell
pip install pieces_os_client
```
## Basic Usage (Recommended)
The Pieces OS Client SDK has a built-in wrapper that simplifies the process of interacting with the Pieces OS server. Here's how you can get started with the wrapper.
### Initialize the Pieces Client
```python
from pieces_os_client.wrapper import PiecesClient
pieces_client = PiecesClient()
```
#### Custom Host URL
When we initialize the Pieces Client, it defaults to `http://localhost:1000` for macOS/Windows and `http://localhost:5323` for Linux. If you have a remote instance of Pieces OS running, you can specify the host URL when initializing the Pieces Client:
```python
from pieces_os_client.wrapper import PiecesClient
# Specify the host URL
host_url = "http://your-host-url:your-port"
pieces_client = PiecesClient(host=host_url)
```
### Create a New Asset
To create a new asset, you can use the `create_asset` method of the Pieces Client. Here's an example of how to create a new asset:
```python
from pieces_os_client.wrapper import PiecesClient
from pieces_os_client import ClassificationSpecificEnum, FragmentMetadata
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 All Assets
To get all your assets, you can use the `assets` method of the Pieces Client. Here's an example of how to get all your assets and print their names:
```python
from pieces_os_client.wrapper import 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()
```
### Ask a Question to Pieces Copilot
To ask a question to Pieces Copilot and stream the response, you can use the `stream_question` method of the Pieces Client. Here's an example of how to ask a question and stream the response:
```python
from pieces_os_client.wrapper import PiecesClient
pieces_client = PiecesClient()
# Set the question you want to ask
question = "What is Object-Oriented Programming?"
# Ask the question and stream the response
for response in pieces_client.copilot.stream_question(question):
if response.question:
# Each answer is a chunk of the entire response to the question
answers = response.question.answers.iterable
for answer in answers:
print(answer.text,end="")
# Close the client
pieces_client.close()
```
### Next Steps
You can explore more features and functionalities of the built-in wrapper by referring to the [Pieces OS Client Wrapper SDK documentation](https://docs.pieces.app/build/sdks/python).
## Advanced Usage (Not recommended)
If you want to use the Pieces OS Client SDK directly without the built-in wrapper, you can follow these steps to get started.
### Getting Started
First, we will create a Python script to test the connection to the Pieces OS server.
Create a python file and add the following code to confirm you can connect to your Pieces OS server:
```python
import pieces_os_client
import platform
# Define the localhost port based on your operating system
# For Linux, use port 5323, for macOS/Windows, use port 1000
platform_info = platform.platform()
if 'Linux' in platform_info:
port = 5323
else:
port = 1000
# The `basePath` defaults to http://localhost:1000, but in this case we are checking the operating system to correctly set the port
configuration = pieces_os_client.Configuration(host=f"http://localhost:{port}")
# Initialize the Pieces ApiClient
api_client = pieces_os_client.ApiClient(configuration)
# Enter a context with an instance of the ApiClient
with pieces_os_client.ApiClient(configuration) as api_client:
# Create an instance of the WellKnown API
api_instance = pieces_os_client.WellKnownApi(api_client)
try:
# Retrieve the (wellknown) health of your Pieces OS server
api_response = api_instance.get_well_known_health()
print("The response of WellKnownApi().get_well_known_health:")
print(api_response) # Response: ok
except Exception as e:
print("Exception when calling WellKnownApi->get_well_known_health: %s\n" % e)
```
A developer documentation that outlines all the ins and outs of our available endpoints can be found [here](https://docs.pieces.app/build/reference/python/).
## Learn More / Support
Explore more about Pieces SDK and get help from the following resources:
- 🚀 [Getting Started with Pieces](https://docs.pieces.app/installation-getting-started/what-am-i-installing)
- 📜 [Pieces Docs](https://docs.pieces.app/build)
- 💬 [Discord Community](https://discord.gg/getpieces)
## License
This repository is available under the [MIT License](./LICENSE).
Raw data
{
"_id": null,
"home_page": "https://pieces.app",
"name": "pieces_os_client",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Pieces",
"author_email": "development@pieces.app",
"download_url": "https://files.pythonhosted.org/packages/f3/4e/6e2177d48b8cd5067d228253a785288a4d1e96c099d41e144e766a59e6e6/pieces_os_client-4.0.4.tar.gz",
"platform": null,
"description": "<h1 align=\"center\">\n <b>\n <a href=\"https://pieces.app\">\n <picture>\n <source srcset=\"https://github.com/user-attachments/assets/6d1c9fc1-11d5-47b0-bb39-a81d40d8fab0\" media=\"(prefers-color-scheme: light)\">\n <source srcset=\"https://github.com/user-attachments/assets/4529e56f-f614-4743-8ca8-33e0c040b069\" media=\"(prefers-color-scheme: dark)\">\n <img src=\"https://github.com/user-attachments/assets/4529e56f-f614-4743-8ca8-33e0c040b069\" height=\"125\" width=\"600\" />\n </picture>\n </a><br>\n </b>\n</h1>\n\n# <p align=\"center\"> Pieces OS Client SDK For Python\n <p align=\"center\">\n <a href=\"https://github.com/pieces-app/pieces-os-client-sdk-for-python/graphs/contributors\" alt=\"GitHub contributors\">\n <img src=\"https://img.shields.io/github/contributors/pieces-app/pieces-os-client-sdk-for-python.svg\" />\n </a>\n <a href=\"https://github.com/pieces-app/pieces-os-client-sdk-for-python/issues\" alt=\"GitHub issues by-label\">\n <img src=\"https://img.shields.io/github/issues/pieces-app/pieces-os-client-sdk-for-python\" />\n </a>\n <a href=\"https://discord.gg/getpieces\" alt=\"Discord\">\n <img src=\"https://img.shields.io/badge/Discord-@layer5.svg?color=7389D8&label&logo=discord&logoColor=ffffff\" />\n </a>\n <a href=\"https://twitter.com/getpieces\" alt=\"Twitter Follow\">\n <img src=\"https://img.shields.io/twitter/follow/pieces.svg?label=Follow\" />\n </a>\n <a href=\"https://github.com/pieces-app/pieces-os-client-sdk-for-python/blob/main/LICENSE\" alt=\"License\">\n <img src=\"https://img.shields.io/github/license/pieces-app/pieces-os-client-sdk-for-python.svg\" />\n </a>\n <a href=\"https://pypi.org/project/pieces_os_client\" >\n <img src=\"https://badge.fury.io/py/pieces-os-client.svg\" />\n </a>\n <a href=\"https://pepy.tech/project/pieces_os_client\" >\n <img src=\"https://static.pepy.tech/badge/pieces_os_client\" />\n </a>\n </p>\n</p>\n\n\n## Introduction\n\nThe Pieces OS Client SDK is a powerful code engine package designed for writing applications on top of Pieces OS. It facilitates communication with a locally hosted server to enable features such as copilot chats, asset saving, and more.\n\n## Features\nThe Pieces SDK offers the following key features:\n\n1. Copilot Chats: Communicate seamlessly with copilot chats functionality.\n2. Asset Management: Save and manage assets and formats efficiently.\n3. Local Server Interaction: Interact with a locally hosted server for various functionalities.\n4. Multi LLMs support: Use any Pieces supported LLM to power your app.\n\n## Installation\n\nTo get started with the Pieces OS Client SDK, follow these steps:\n\n1. **Download Pieces OS**: Pieces OS serves as the primary backend service, providing essential functionality for the SDK. Download the appropriate version for your operating system:\n - [macOS](https://docs.pieces.app/installation-getting-started/macos) \n - [Windows](https://docs.pieces.app/installation-getting-started/windows) \n - [Linux](https://docs.pieces.app/installation-getting-started/linux)\n\n2. **Install the SDK**: Use pip to install the Pieces OS Client SDK package:\n ```shell\n pip install pieces_os_client\n ```\n\n## Basic Usage (Recommended)\n\nThe Pieces OS Client SDK has a built-in wrapper that simplifies the process of interacting with the Pieces OS server. Here's how you can get started with the wrapper.\n\n### Initialize the Pieces Client\n\n```python\nfrom pieces_os_client.wrapper import PiecesClient\n\npieces_client = PiecesClient()\n```\n\n#### Custom Host URL\n\nWhen we initialize the Pieces Client, it defaults to `http://localhost:1000` for macOS/Windows and `http://localhost:5323` for Linux. If you have a remote instance of Pieces OS running, you can specify the host URL when initializing the Pieces Client:\n\n```python\nfrom pieces_os_client.wrapper import PiecesClient\n\n# Specify the host URL\nhost_url = \"http://your-host-url:your-port\"\n\npieces_client = PiecesClient(host=host_url)\n```\n\n### Create a New Asset\n\nTo create a new asset, you can use the `create_asset` method of the Pieces Client. Here's an example of how to create a new asset:\n\n```python\nfrom pieces_os_client.wrapper import PiecesClient\nfrom pieces_os_client import ClassificationSpecificEnum, FragmentMetadata\n\npieces_client = PiecesClient()\n\n# Set the content and metadata for the new asset\ncontent = \"print('Hello, World!')\"\nmetadata = FragmentMetadata(ext=ClassificationSpecificEnum.PY) # optional metadata\n\n# Create the new asset using the content and metadata\nnew_asset_id = pieces_client.create_asset(content, metadata)\nprint(f\"Created asset with ID: {new_asset_id}\")\n\n# Close the client\npieces_client.close()\n```\n\n### Get All Assets\n\nTo get all your assets, you can use the `assets` method of the Pieces Client. Here's an example of how to get all your assets and print their names:\n\n```python\nfrom pieces_os_client.wrapper import PiecesClient\n\npieces_client = PiecesClient()\n\n# Get all assets and print their names\nassets = pieces_client.assets()\nfor asset in assets:\n print(f\"Asset Name: {asset.name}\")\n\n# Close the client\npieces_client.close()\n```\n\n### Ask a Question to Pieces Copilot\n\nTo ask a question to Pieces Copilot and stream the response, you can use the `stream_question` method of the Pieces Client. Here's an example of how to ask a question and stream the response:\n\n```python\nfrom pieces_os_client.wrapper import PiecesClient\n\npieces_client = PiecesClient()\n\n# Set the question you want to ask\nquestion = \"What is Object-Oriented Programming?\"\n\n# Ask the question and stream the response\nfor response in pieces_client.copilot.stream_question(question):\n if response.question:\n # Each answer is a chunk of the entire response to the question\n answers = response.question.answers.iterable\n for answer in answers:\n print(answer.text,end=\"\")\n\n# Close the client\npieces_client.close()\n```\n\n### Next Steps\n\nYou can explore more features and functionalities of the built-in wrapper by referring to the [Pieces OS Client Wrapper SDK documentation](https://docs.pieces.app/build/sdks/python).\n\n## Advanced Usage (Not recommended)\n\nIf you want to use the Pieces OS Client SDK directly without the built-in wrapper, you can follow these steps to get started.\n\n### Getting Started\n\nFirst, we will create a Python script to test the connection to the Pieces OS server.\n\nCreate a python file and add the following code to confirm you can connect to your Pieces OS server:\n\n```python\nimport pieces_os_client\nimport platform\n\n# Define the localhost port based on your operating system\n# For Linux, use port 5323, for macOS/Windows, use port 1000\nplatform_info = platform.platform()\nif 'Linux' in platform_info:\n port = 5323\nelse:\n port = 1000\n\n# The `basePath` defaults to http://localhost:1000, but in this case we are checking the operating system to correctly set the port\nconfiguration = pieces_os_client.Configuration(host=f\"http://localhost:{port}\")\n\n# Initialize the Pieces ApiClient\napi_client = pieces_os_client.ApiClient(configuration)\n\n# Enter a context with an instance of the ApiClient\nwith pieces_os_client.ApiClient(configuration) as api_client:\n # Create an instance of the WellKnown API\n api_instance = pieces_os_client.WellKnownApi(api_client)\n\n try:\n # Retrieve the (wellknown) health of your Pieces OS server\n api_response = api_instance.get_well_known_health()\n print(\"The response of WellKnownApi().get_well_known_health:\")\n print(api_response) # Response: ok\n except Exception as e:\n print(\"Exception when calling WellKnownApi->get_well_known_health: %s\\n\" % e)\n```\n\nA developer documentation that outlines all the ins and outs of our available endpoints can be found [here](https://docs.pieces.app/build/reference/python/).\n\n## Learn More / Support\nExplore more about Pieces SDK and get help from the following resources:\n\n- \ud83d\ude80 [Getting Started with Pieces](https://docs.pieces.app/installation-getting-started/what-am-i-installing)\n- \ud83d\udcdc [Pieces Docs](https://docs.pieces.app/build)\n- \ud83d\udcac [Discord Community](https://discord.gg/getpieces)\n\n## License\n\nThis repository is available under the [MIT License](./LICENSE).\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A powerful code engine package for writing applications on top of Pieces OS",
"version": "4.0.4",
"project_urls": {
"Documentation": "https://docs.pieces.app/build/reference/python/",
"Homepage": "https://pieces.app",
"Repository": "https://github.com/pieces-app/pieces-os-client-sdk-for-python",
"issues": "https://github.com/pieces-app/pieces-os-client-sdk-for-python/issues"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cef600e884ea528b91cf04f91f24825ecec6b1acbbd730ac3f9af623bde6ce51",
"md5": "fae0d98f49796b33a14d28287fc79364",
"sha256": "0a74c22311fd2a068633413655faf97c4b7e448e9eca02652facd4a1a16d601b"
},
"downloads": -1,
"filename": "pieces_os_client-4.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fae0d98f49796b33a14d28287fc79364",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 1075048,
"upload_time": "2024-11-15T12:18:41",
"upload_time_iso_8601": "2024-11-15T12:18:41.665107Z",
"url": "https://files.pythonhosted.org/packages/ce/f6/00e884ea528b91cf04f91f24825ecec6b1acbbd730ac3f9af623bde6ce51/pieces_os_client-4.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f34e6e2177d48b8cd5067d228253a785288a4d1e96c099d41e144e766a59e6e6",
"md5": "3f918898dbfce7a696aa1a0b0ca27d25",
"sha256": "0278455867598bcb80bf7839a721eacc1984c29d97c4fcf4383c380e334022ee"
},
"downloads": -1,
"filename": "pieces_os_client-4.0.4.tar.gz",
"has_sig": false,
"md5_digest": "3f918898dbfce7a696aa1a0b0ca27d25",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 334389,
"upload_time": "2024-11-15T12:18:44",
"upload_time_iso_8601": "2024-11-15T12:18:44.199853Z",
"url": "https://files.pythonhosted.org/packages/f3/4e/6e2177d48b8cd5067d228253a785288a4d1e96c099d41e144e766a59e6e6/pieces_os_client-4.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-15 12:18:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pieces-app",
"github_project": "pieces-os-client-sdk-for-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pieces_os_client"
}