Skip to main content

Python client for using Code Mode via PCTX

Project description

PCTX Python Client

Python client for using Code Mode via PCTX - execute JavaScript code with access to your Python functions.

Installation

pip install pctx-client

Quick Start

  1. Install PCTX server (currently release candidate)
# cURL
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/portofcontext/pctx/releases/download/v0.3.0-rc.1/pctx-installer.sh | sh

# npm
npm install @portofcontext/pctx@0.3.0-rc.1
  1. Install Python pctx with the langchain extra (this example uses a groq model but you can use any model supported by langchain)
pip install pctx-client[langchain] langchain  langchain-groq
  1. Set the Groq API key (create a free account to get a key)
export GROQ_API_KEY=*****
  1. Start the Code Mode server for agents
pctx agent start
  1. Define and run main.py
import asyncio

from pctx_client import Pctx, tool
from langchain.agents import create_agent

# Define your tools
@tool
def get_weather(city: str) -> str:
    """Get weather for a given city."""
    return f"It's always sunny in {city}!"


@tool
def get_time(city: str) -> str:
    """Get time for a given city."""
    return f"It is midnight in {city}!"


async def main():
    # Initialize client with your tools
    p = Pctx(tools=[get_weather, get_time])

    # Define your agent
    agent = create_agent(
        model="groq:openai/gpt-oss-120b", # choose any model supported by langchain!
        tools=p.langchain_tools(),
        system_prompt="You are a helpful assistant",
    )

    # Connect to PCTX
    await p.connect()

    result = await agent.ainvoke(
        {
            "messages": [
                {"role": "user", "content": "what is the weather and time in nyc"}
            ]
        }
    )

    print(result)

    # Disconnect when done
    await p.disconnect()

if __name__ == "__main__":
    asyncio.run(main())

Features

  • Tool Decorator: Easily expose Python functions as callable tools
  • Async Support: Full async/await support for non-blocking operations
  • MCP Server Integration: Connect to MCP servers for extended functionality

Usage

Defining Tools

Use the @tool decorator to expose Python functions:

@tool("function_name", namespace="namespace")
def my_function(arg1: str, arg2: int) -> str:
    """Function description"""
    return f"{arg1}: {arg2}"

List Available Functions

functions = await p.list_functions()
print(functions.code)

Get Function Details

details = await p.get_function_details(["Namespace.functionName"])
print(details.code)

Optional Integrations

LangChain

pip install pctx[langchain]

CrewAI

pip install pctx[crewai]

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

pctx_client-0.1.0rc2.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pctx_client-0.1.0rc2-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file pctx_client-0.1.0rc2.tar.gz.

File metadata

  • Download URL: pctx_client-0.1.0rc2.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pctx_client-0.1.0rc2.tar.gz
Algorithm Hash digest
SHA256 4f4f3e695a7e78637aab16c9cef68820f0f45d66f815390d5faf05632219b495
MD5 c420d7a964b194951e9908a63e61fe8a
BLAKE2b-256 8a9f7629d6c4bde0328e9c456b1574d97262644a82ff7a9255652c33c30f843a

See more details on using hashes here.

File details

Details for the file pctx_client-0.1.0rc2-py3-none-any.whl.

File metadata

  • Download URL: pctx_client-0.1.0rc2-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pctx_client-0.1.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 f115676d856e708f8d09d2ef7497fc09d6ae945e4411734f060a88c93f9e9c1c
MD5 0f0bc74c8ed3310aa5a5cd89d8da01ec
BLAKE2b-256 5bc142fc850b41085a2589291c92278b6b6c4c89edf0012d1027c4544825e768

See more details on using hashes here.

Supported by

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