# Portia SDK Python
## Usage
### Installation
```bash
pip install portia-sdk-python
```
### Simple Usage
```python
from portia.runner import Runner, RunnerConfig
runner = Runner(config=RunnerConfig(portia_api_key='123'))
runner.run_query("Add 1 and 2")
```
### With Custom Local Tools and Disk Storage
```python
from portia.runner import Runner, RunnerConfig, StorageClass
from portia.tool import Tool
from portia.tool_registry import InMemoryToolRegistry
# Create a local tool
class AdditionTool(Tool):
id: str = "addition_tool"
name: str = "Addition Tool"
description: str = "Takes two numbers and adds them together"
def run(self, a: int, b: int) -> int:
return a + b
# Create the ToolRegistry with the tool
tool_registry = InMemoryToolRegistry.from_local_tools([AdditionTool()])
runner = Runner(config=Config(), tool_registry=tool_registry)
runner.run_query("Add 1 and 2")
```
### Hybrid Approach
Multiple registries can be combined to give the power of Portia Cloud with the customization of local tools:
```python
from portia.runner import Runner, RunnerConfig
from portia.tool import Tool
from portia.tool_registry import InMemoryToolRegistry, PortiaToolRegistry
# Create a local tool
class AdditionTool(Tool):
id: str = "add_tool"
name: str = "Add Tool"
description: str = "Takes two numbers and adds them together"
def run(self, a: int, b: int) -> int:
return a + b
# Create the ToolRegistry with the tool
local_tool_registry = InMemoryToolRegistry.from_local_tools([AdditionTool()])
remote_tool_registry = PortiaToolRegistry(api_key="123")
tool_registry = local_tool_registry + remote_tool_registry
config = Config()
runner = Runner(config=config, tool_registry=tool_registry)
runner.run_query("Add 1 and 2")
```
## Tests
Run tests with `poetry run pytest`.
## Release
Releases are controlled via Github Actions and the version field of the `pyproject.toml`. To release:
1. Create a PR that updates the version field in the `pyproject.toml`.
2. Merge the PR to main.
3. Github Actions will create a new tag and push the new version to PyPi.
## CLI
To test the CLI locally run
```bash
pip install -e .
export OPENAI_API_KEY=$KEY
portia-cli run "add 4 + 8"
```
Raw data
{
"_id": null,
"home_page": "https://www.portialabs.ai/",
"name": "portia-sdk-python",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.12",
"maintainer_email": null,
"keywords": "LLM, agentic, workflow",
"author": "Tech",
"author_email": "tech@portialabs.ai",
"download_url": "https://files.pythonhosted.org/packages/2a/80/ac0d2f6cab26d09ce602a116a98a1b6f45a91222ad5f68fb376763890622/portia_sdk_python-0.0.1a2.tar.gz",
"platform": null,
"description": "# Portia SDK Python\n\n\n## Usage\n\n### Installation\n\n```bash\npip install portia-sdk-python \n```\n\n\n### Simple Usage\n\n```python\nfrom portia.runner import Runner, RunnerConfig\n\nrunner = Runner(config=RunnerConfig(portia_api_key='123'))\nrunner.run_query(\"Add 1 and 2\")\n```\n\n\n### With Custom Local Tools and Disk Storage\n\n```python\nfrom portia.runner import Runner, RunnerConfig, StorageClass\nfrom portia.tool import Tool\nfrom portia.tool_registry import InMemoryToolRegistry\n\n# Create a local tool\nclass AdditionTool(Tool):\n id: str = \"addition_tool\"\n name: str = \"Addition Tool\"\n description: str = \"Takes two numbers and adds them together\"\n\n def run(self, a: int, b: int) -> int:\n return a + b\n\n\n# Create the ToolRegistry with the tool\ntool_registry = InMemoryToolRegistry.from_local_tools([AdditionTool()])\n\nrunner = Runner(config=Config(), tool_registry=tool_registry)\nrunner.run_query(\"Add 1 and 2\")\n```\n\n### Hybrid Approach\n\nMultiple registries can be combined to give the power of Portia Cloud with the customization of local tools:\n\n```python\nfrom portia.runner import Runner, RunnerConfig\nfrom portia.tool import Tool\nfrom portia.tool_registry import InMemoryToolRegistry, PortiaToolRegistry\n\n# Create a local tool\nclass AdditionTool(Tool):\n id: str = \"add_tool\"\n name: str = \"Add Tool\"\n description: str = \"Takes two numbers and adds them together\"\n\n def run(self, a: int, b: int) -> int:\n return a + b\n\n\n# Create the ToolRegistry with the tool\nlocal_tool_registry = InMemoryToolRegistry.from_local_tools([AdditionTool()])\n\nremote_tool_registry = PortiaToolRegistry(api_key=\"123\")\n\ntool_registry = local_tool_registry + remote_tool_registry\n\nconfig = Config()\nrunner = Runner(config=config, tool_registry=tool_registry)\nrunner.run_query(\"Add 1 and 2\")\n```\n\n\n## Tests\n\nRun tests with `poetry run pytest`.\n\n## Release\n\nReleases are controlled via Github Actions and the version field of the `pyproject.toml`. To release:\n\n1. Create a PR that updates the version field in the `pyproject.toml`.\n2. Merge the PR to main.\n3. Github Actions will create a new tag and push the new version to PyPi.\n\n## CLI \n\nTo test the CLI locally run \n\n```bash\npip install -e . \nexport OPENAI_API_KEY=$KEY\nportia-cli run \"add 4 + 8\"\n```",
"bugtrack_url": null,
"license": null,
"summary": "Portia Labs Python SDK for building agentic workflows.",
"version": "0.0.1a2",
"project_urls": {
"Documentation": "https://www.portialabs.ai/docs",
"Homepage": "https://www.portialabs.ai/",
"Repository": "https://pypi.org/TomPortia/portia-sdk-python/"
},
"split_keywords": [
"llm",
" agentic",
" workflow"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f2cfea5242436d1028abfee16c91688afdd4e4dee3758235d597a347a3e0ccd4",
"md5": "9fb16565d55f9df6f79c12276b39ded7",
"sha256": "3eba204ff16d2deb078f9ea9ce429e91d82a928f76d8f53fcbcdf45b96e0ccbc"
},
"downloads": -1,
"filename": "portia_sdk_python-0.0.1a2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9fb16565d55f9df6f79c12276b39ded7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.12",
"size": 32381,
"upload_time": "2024-12-20T10:38:58",
"upload_time_iso_8601": "2024-12-20T10:38:58.955282Z",
"url": "https://files.pythonhosted.org/packages/f2/cf/ea5242436d1028abfee16c91688afdd4e4dee3758235d597a347a3e0ccd4/portia_sdk_python-0.0.1a2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2a80ac0d2f6cab26d09ce602a116a98a1b6f45a91222ad5f68fb376763890622",
"md5": "b0eddf254a71877bacd3160172837de2",
"sha256": "c72803637d61599316ae8174810d9f8b48e70005861922b9f2fa3adafa1830fb"
},
"downloads": -1,
"filename": "portia_sdk_python-0.0.1a2.tar.gz",
"has_sig": false,
"md5_digest": "b0eddf254a71877bacd3160172837de2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.12",
"size": 23141,
"upload_time": "2024-12-20T10:39:01",
"upload_time_iso_8601": "2024-12-20T10:39:01.365841Z",
"url": "https://files.pythonhosted.org/packages/2a/80/ac0d2f6cab26d09ce602a116a98a1b6f45a91222ad5f68fb376763890622/portia_sdk_python-0.0.1a2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-20 10:39:01",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "portia-sdk-python"
}