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
from langgraph.prebuilt import create_react_agent

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.5.tar.gz (11.3 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.5-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: integry-0.0.5.tar.gz
  • Upload date:
  • Size: 11.3 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.5.tar.gz
Algorithm Hash digest
SHA256 fd25fead529c655aaf07190f0b1e8e2c35fe88b4768f86ba1d4f202c77055114
MD5 070c0cff4826cb4dad3543057f346d65
BLAKE2b-256 e978e64c1ee3a3e5d015f8a802d814a982e3fa5c1018ca0ff1c6dca10a345992

See more details on using hashes here.

File details

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

File metadata

  • Download URL: integry-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 14.8 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 27175d96d5455ddfd992ba270954dce275ae9b2e1768a0b9fb1837465769d6df
MD5 2723dc235b8e9cbfedde68ff2d5ed840
BLAKE2b-256 caa715d211f3124141f5e8fbba4fb7c7d69b5f27ac41c6a0843349c654156904

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