Skip to main content

The official Python library for the Integry API

Project description

Integry Python API Library

PyPI version

The Python API library allows access to Integry REST API from Python programs.

Installation

# install from PyPI
pip install integry

Usage with Agent Frameworks

1. LangChain/LangGraph

import os
from integry import Integry
from langchain_core.messages import SystemMessage, HumanMessage
from langchain_openai import ChatOpenAI
from langchain_core.tools import StructuredTool

user_id = "your user's ID"

# Initialize the client
integry = Integry(
    app_key=os.environ.get("INTEGRY_APP_SECRET"),
    app_secret=os.environ.get("INTEGRY_APP_KEY"),
)

slack_post_message = await integry.functions.get("slack-post-message", user_id)

llm = ChatOpenAI(
    model="gpt-4o",
    api_key=os.environ.get("OPENAI_API_KEY"),
)

tool = slack_post_message.as_langchain_tool(StructuredTool.from_function, user_id)

agent = create_react_agent(
    tools=[tool],
    model=llm,
)

await agent.ainvoke({
    "messages": [
        SystemMessage(content="You are a helpful assistant"),
        HumanMessage(content="Say hello to my team on slack"),
    ]
})

2. CrewAI

import os
from integry import Integry
from langchain_openai import ChatOpenAI

user_id = "your user's ID"

# Initialize the client
integry = Integry(
    app_key=os.environ.get("INTEGRY_APP_SECRET"),
    app_secret=os.environ.get("INTEGRY_APP_KEY"),
)

slack_post_message = await integry.functions.get("slack-post-message", user_id)

tool = slack_post_message.as_langchain_tool(StructuredTool.from_function, user_id)

llm = ChatOpenAI(
    model="gpt-4o",
    api_key=SecretStr(os.environ.get("OPENAI_API_KEY")),
)

crewai_agent = Agent(
    role="Integration Assistant",
    goal="You are a helpful assistant",
    backstory="You help users make actions on various apps",
    verbose=True,
    tools=[tool],
    llm=llm,
)

task = Task(
    description="Say hello to my team on slack",
    agent=crewai_agent,
    expected_output="Status of the operation"
)

crew = Crew(
    agents = [crewai_agent],
    tasks = [task]
)

result = crew.kickoff()

3. Letta

import os
from integry import Integry

user_id = "your user's ID"

# Initialize the client
integry = Integry(
    app_key=os.environ.get("INTEGRY_APP_SECRET"),
    app_secret=os.environ.get("INTEGRY_APP_KEY"),
)

slack_post_message = await integry.functions.get("slack-post-message", user_id)

client = create_client()

agent_state = client.create_agent(
    name="Integration Assistant", 
)

tool = slack_post_message.as_langchain_tool(StructuredTool.from_function, user_id)
client.add_tool(tool)

response = client.send_message(agent_id=agent_state.id, role="user", message="say hello to my team on Slack")

4. AutoGen (WIP)

import os
from integry import Integry

from autogen import AssistantAgent, UserProxyAgent

user_id = "your user's ID"

# Initialize the client
integry = Integry(
    app_key=os.environ.get("INTEGRY_APP_SECRET"),
    app_secret=os.environ.get("INTEGRY_APP_KEY"),
)

llm_config = {
    "config_list": [
        {
            "model": "gpt-4o-mini",
            "api_key": "<your-api-key>",
        }
    ]
}

chatbot = AssistantAgent(
    "chatbot",
    system_message="Reply TERMINATE when the task is done or when user's content is empty",
    llm_config=llm_config,
)

user_proxy = UserProxyAgent(
    name="User",
    is_termination_msg=lambda x: x.get("content", "")
    and "TERMINATE" in x.get("content", ""),
    human_input_mode="NEVER",
    code_execution_config={"use_docker": False},
)

toolset.register_tools(apps=[App.GITHUB], caller=chatbot, executor=user_proxy)

response = user_proxy.initiate_chat(chatbot, message="say hello to my team on Slack")

Prediction

import os
from integry import Integry

user_id = "your user's ID"

# Initialize the client
integry = Integry(
    app_secret=os.environ.get("INTEGRY_APP_KEY"),
    app_key=os.environ.get("INTEGRY_APP_SECRET"),
)

# Get the most relevant function
predictions = await integry.functions.predict(
    prompt="say hello to my team on Slack", user_id=user_id, predict_arguments=True
)

if predictions:
    function = predictions[0]
    # Call the function
    await function(user_id, function.arguments)

Pagination

List methods are paginated and allow you to iterate over data without handling pagination manually.

from integry import Integry

user_id = "your user's ID"

integry = Integry(
    app_secret=os.environ.get("INTEGRY_APP_KEY"),
    app_key=os.environ.get("INTEGRY_APP_SECRET"),
)

async for function in integry.functions.list(user_id):
    # do something with function
    print(function.name)

If you want to control pagination, you can fetch individual pages by using the cursor returned by the previous page.

from integry import Integry

user_id = "your user's ID"

integry = Integry(
    app_secret=os.environ.get("INTEGRY_APP_KEY"),
    app_key=os.environ.get("INTEGRY_APP_SECRET"),
)

first_page = await integry.apps.list(user_id)

second_page = await integry.apps.list(user_id, cursor=first_page.cursor)

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

integry-0.0.3.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

integry-0.0.3-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file integry-0.0.3.tar.gz.

File metadata

  • Download URL: integry-0.0.3.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for integry-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ae5f0aa3733b344350f3aa7974d42fb3bca33813659599604a379ec21f5547cf
MD5 526798d236b2c3b2bde0860f5b2a1102
BLAKE2b-256 75bf69f5d08d73acfd3607d05bb945b49f336753d9f271b4daafeecbb7a51793

See more details on using hashes here.

File details

Details for the file integry-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: integry-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for integry-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2cb69eea553fd65be63f18d6956c09e26b98a1450a267e1baf7c30a00fefdbbe
MD5 321bd2c4a393832239a2b2691c9233e3
BLAKE2b-256 05eafaead260b70092ab22e834b20d4db8a14ace6e7fafeea46bfe58f0f818f7

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