Skip to main content

Python SDK for Port42 — connect external agents to your macOS companion

Project description

port42

Python SDK for Port42 — connect external agents to your macOS companion.

Install

pip install port42

Quickstart

from port42 import Agent

agent = Agent("my-agent", channels=["#general"])

@agent.on_mention
def handle(msg):
    return f"Hello {msg.sender}!"

agent.run()

Port42 must be running. The agent connects via WebSocket and appears in your companion list.

With LangChain

pip install 'port42[langchain]'
from port42 import Agent
from port42.langchain import Port42CallbackHandler
from langchain_anthropic import ChatAnthropic

agent = Agent("assistant", channels=["#general"])
handler = Port42CallbackHandler(agent)

chain = ChatAnthropic(model="claude-sonnet-4-5")

@agent.on_mention
def handle(msg):
    result = chain.invoke(msg.text, config={"callbacks": [handler]})
    return result.content

agent.run()

CLI — send messages and interact from the terminal

pip install 'port42[cli]'

Get an invite URL from Port42: right-click a channel → Add Companion → Remote → Connect LLM CLI.

# Send a message
port42 send "hello" --invite "<url>" --owner "gordon" --name "$(basename $PWD)"

# Ask an agent and wait for its reply (prints decrypted response)
port42 ask "@agent what is the status?" --invite "<url>" --owner "gordon" --timeout 120

# Pipe command output to a channel (one message on EOF)
./build.sh 2>&1 | port42 bridge --invite "<url>" --owner "gordon"

# Stream live output line-by-line as it arrives
tail -f server.log | port42 bridge --invite "<url>" --owner "gordon" --live

The invite URL carries the gateway address, channel ID, and E2E encryption key — no separate configuration needed.

Scaffold a project

pip install 'port42[cli]'
port42 init my-agent
cd my-agent && python agent.py

Templates: basic, langchain, pipeline

Bridge APIs

Once connected, your agent can call Port42 device APIs:

agent.terminal_exec("ls ~/Desktop")
agent.screen_capture(scale=0.5)
agent.notify("Done", body="Pipeline complete")
agent.port_push(port_id, {"key": "value"})
agent.rest_call("https://api.example.com/data", secret="MY_API_KEY")

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

port42-0.2.7.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

port42-0.2.7-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file port42-0.2.7.tar.gz.

File metadata

  • Download URL: port42-0.2.7.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for port42-0.2.7.tar.gz
Algorithm Hash digest
SHA256 034b6ed05e5e2feafa8f46bc05662d49332e291738c7d1e97748cedabfc9c862
MD5 22e9b1f4079f9173d77df30eafade114
BLAKE2b-256 fec1eae075a5872e66e732abf7f5d0d1c88c7afb415243f53f3b6116040c8c7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for port42-0.2.7.tar.gz:

Publisher: publish.yml on gordonmattey/port42-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file port42-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: port42-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for port42-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 5719ab0f3f0687de86a35f9e9987f38967c224a7ba4c037163877a3cd8b174f8
MD5 656e069857e68230bdd52452128e8b38
BLAKE2b-256 6f826f63676190b840355052d498d00799c3a29f872051d0c662fb1faee949d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for port42-0.2.7-py3-none-any.whl:

Publisher: publish.yml on gordonmattey/port42-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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