Skip to main content

A powerful code engine package for writing applications on top of Pieces OS

Project description


Pieces OS Client SDK For Python

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:

  2. Install the SDK: Use pip to install the Pieces OS Client SDK package:

    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

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:

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:

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:

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:

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.

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:

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.

Learn More / Support

Explore more about Pieces SDK and get help from the following resources:

License

This repository is available under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pieces_os_client-4.0.4.tar.gz (334.4 kB view details)

Uploaded Source

Built Distribution

pieces_os_client-4.0.4-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file pieces_os_client-4.0.4.tar.gz.

File metadata

  • Download URL: pieces_os_client-4.0.4.tar.gz
  • Upload date:
  • Size: 334.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.9.20 Linux/6.5.0-1025-azure

File hashes

Hashes for pieces_os_client-4.0.4.tar.gz
Algorithm Hash digest
SHA256 0278455867598bcb80bf7839a721eacc1984c29d97c4fcf4383c380e334022ee
MD5 3f918898dbfce7a696aa1a0b0ca27d25
BLAKE2b-256 f34e6e2177d48b8cd5067d228253a785288a4d1e96c099d41e144e766a59e6e6

See more details on using hashes here.

File details

Details for the file pieces_os_client-4.0.4-py3-none-any.whl.

File metadata

  • Download URL: pieces_os_client-4.0.4-py3-none-any.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.9.20 Linux/6.5.0-1025-azure

File hashes

Hashes for pieces_os_client-4.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0a74c22311fd2a068633413655faf97c4b7e448e9eca02652facd4a1a16d601b
MD5 fae0d98f49796b33a14d28287fc79364
BLAKE2b-256 cef600e884ea528b91cf04f91f24825ecec6b1acbbd730ac3f9af623bde6ce51

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page