Skip to main content

Python Client SDK Generated by Speakeasy.

Project description

gram-ai

Developer-friendly Python SDK to interact with Gram toolsets. Gram allows you to use your agentic tools in a variety of different frameworks and protocols. Gram tools can be used with pretty much any model that supports function calling via a chat completions or responses style API.

SDK Installation

[!NOTE] Python version upgrade policy

Once a Python version reaches its official end of life date, a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.

The SDK can be installed with either pip or poetry package managers.

PIP

PIP is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.

pip install gram-ai

Poetry

Poetry is a modern tool that simplifies dependency management and package publishing by using a single pyproject.toml file to handle project metadata and dependencies.

poetry add gram-ai

OpenAI Agents SDK

import asyncio
import os
from agents import Agent, Runner, set_default_openai_key
from gram_ai.openai_agents import GramOpenAIAgents

key = os.getenv("GRAM_API_KEY")

gram = GramOpenAIAgents(
    api_key=key,
)

set_default_openai_key(os.getenv("OPENAI_API_KEY"))

agent = Agent(
    name="Assistant",
    tools=gram.tools(
        project="default",
        toolset="default",
        environment="default",
    ),
)


async def main():
    result = await Runner.run(
        agent,
        "Can you tell me what tools you have available?",
    )
    print(result.final_output)


if __name__ == "__main__":
    asyncio.run(main()) 

LangChain

import asyncio
import os
from langchain import hub
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_functions_agent
from gram_ai.langchain import GramLangchain

key = os.getenv("GRAM_API_KEY")

gram = GramLangchain(api_key=key)

llm = ChatOpenAI(
    model="gpt-4",
    temperature=0,
    openai_api_key=os.getenv("OPENAI_API_KEY")
)

tools = gram.tools(
    project="default",
    toolset="default",
    environment="default",
)

prompt = hub.pull("hwchase17/openai-functions-agent")

agent = create_openai_functions_agent(llm=llm, tools=tools, prompt=prompt)

agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=False)

async def main():
    response = await agent_executor.ainvoke({
        "input": "Can you tell me what tools you have available?"
    })
    print(response)

if __name__ == "__main__":
    asyncio.run(main())

OpenAI Function Calling

import os
from openai import OpenAI
from gram_ai.openai import OpenAIAdapter

key = os.getenv("GRAM_API_KEY")

gram = OpenAIAdapter(api_key=key)
openai_client = OpenAI(api_key=openai_api_key)
openai_tools = gram.tools(project="default", toolset="gtm", environment="default")

response = openai_client.chat.completions.create(
    model="gpt-4o",
    prompt: "Can you tell me what tools you have available?"
    tools=openai_tools_data.tools,
    tool_choice="auto",
)

Vanilla Function Calling

import os
from gram_ai.function_calling import GramFunctionCalling

key = os.getenv("GRAM_API_KEY")

# vanilla client that matches the function calling interface for direct use with model provider APIs
gram = GramFunctionCalling(api_key=key)

tools = gram.tools(
    project="default",
    toolset="default",
    environment="default",
)

# exposes name, description, parameters, and an execute and aexecute (async) function
print(tools[0].name)
print(tools[0].description)
print(tools[0].parameters)
print(tools[0].execute)
print(tools[0].aexecute)

Passing in User Defined Environment Variables

If preferred, it's possible to pass in user defined environment variables into tools calls rather than using hosted gram environments.

import asyncio
import os
from agents import Agent, Runner, set_default_openai_key
from gram_ai.openai_agents import GramOpenAIAgents

key = os.getenv("GRAM_API_KEY")

gram = GramOpenAIAgents(
    api_key=key,
    environment_variables= {
        "MY_TOOL_TOKEN": "VALUE"
    }
)

set_default_openai_key(os.getenv("OPENAI_API_KEY"))

agent = Agent(
    name="Assistant",
    tools=gram.tools(
        project="default",
        toolset="default",
    ),
)


async def main():
    result = await Runner.run(
        agent,
        "Can you tell me what tools you have available?",
    )
    print(result.final_output)


if __name__ == "__main__":
    asyncio.run(main()) 

MCP

Gram also instantly allows you to expose and use any toolset as a hosted MCP server.

{
    "mcpServers": {
      "GramTest": {
        "command": "npx",
        "args": [
          "mcp-remote",
          "https://app.getgram.ai/mcp/default/default/default",
          "--allow-http",
          "--header",
          "Authorization:${GRAM_KEY}"
        ],
        "env": {
          "GRAM_KEY": "Bearer <your-key-here>"
        }
      }
    }
  }

You also have the option to add a unique slug to these servers and make them publicly available to pass your own credentials.

{
    "mcpServers": {
      "GramSlack": {
        "command": "npx",
        "args": [
          "mcp-remote",
          "https://app.getgram.ai/mcp/speakeasy-team-default",
          "--allow-http",
          "--header",
          "MCP-SPEAKEASY_YOUR_TOOLSET_CRED:${VALUE}"
        ]
      }
    }
  }

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

gram_ai-0.3.0.tar.gz (34.0 kB view details)

Uploaded Source

Built Distribution

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

gram_ai-0.3.0-py3-none-any.whl (52.8 kB view details)

Uploaded Python 3

File details

Details for the file gram_ai-0.3.0.tar.gz.

File metadata

  • Download URL: gram_ai-0.3.0.tar.gz
  • Upload date:
  • Size: 34.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.9.23 Linux/6.8.0-1029-azure

File hashes

Hashes for gram_ai-0.3.0.tar.gz
Algorithm Hash digest
SHA256 101f9ce8286efa267cc43efe04e44c60bc35d0c32a16d2fcce3611d49ab32ff9
MD5 3690120ccb94f301a42d7f64ac4271af
BLAKE2b-256 f62da64d0dc987eef290d3c22e157ae12224b966422a4d9c3d93a11569c32f6d

See more details on using hashes here.

File details

Details for the file gram_ai-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: gram_ai-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 52.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.9.23 Linux/6.8.0-1029-azure

File hashes

Hashes for gram_ai-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0428e65eac1bbad4c0631444041141f838cbeafd5da9921b7347d56146ed496a
MD5 d35f68d34d211ba7618eb1defadae7c3
BLAKE2b-256 4d1df3242403f16b71340438e0246820bd2fb1091ab8d4673de1db8d3647d46d

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