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
- Install PCTX server
# Homebrew
brew install portofcontext/tap/pctx
# cURL
curl --proto '=https' --tlsv1.2 -LsSf https://raw.githubusercontent.com/portofcontext/pctx/main/install.sh | sh
# npm
npm i -g @portofcontext/pctx
- Install Python pctx with the langchain extra
pip install pctx-client[langchain] langchain
- Start the Code Mode server for agents
pctx agent start
- 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="anthropic:claude-sonnet-4-5-20250929", # 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
Release history Release notifications | RSS feed
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.0rc1.tar.gz
(10.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pctx_client-0.1.0rc1.tar.gz.
File metadata
- Download URL: pctx_client-0.1.0rc1.tar.gz
- Upload date:
- Size: 10.2 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c01d43c1d2a44c731effdb771a3e36462934785cb51babf1624869f86021d9e
|
|
| MD5 |
db5dec0747ecf95155ad278d8a63edc4
|
|
| BLAKE2b-256 |
afbaf72a38ae596e357a8cd0013fa7ce2eb58eb3c3bcee6cb803da18fcb869ec
|
File details
Details for the file pctx_client-0.1.0rc1-py3-none-any.whl.
File metadata
- Download URL: pctx_client-0.1.0rc1-py3-none-any.whl
- Upload date:
- Size: 12.9 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10823239048079962d45a10e96e69bb6680484e82c25a592278592c5662e4570
|
|
| MD5 |
3b954083ae277ff47ec7dffb4436a09d
|
|
| BLAKE2b-256 |
1d365e032567ad77477e7a18f5afa8bd3b79573f7c25f8ab34c68fa1674b5930
|