Skip to main content

PipesHub Python SDK

PyPI version Python 3.10+ License

This is the official Python SDK for PipesHub. Search your company's knowledge and get answers with citations, run agents, and manage knowledge bases and connectors, all from your Python code.

PipesHub connects workplace apps such as Google Drive, Slack, Confluence and Jira and indexes their content. The SDK supports Python 3.10 and later, has type hints for every request and response, and offers both synchronous and asynchronous clients.

Documentation

  • API reference: the PipesHub HTTP API.
  • Available methods: every SDK method, linked to its parameters, response and errors.
  • Examples: runnable programs for search, chat, agents, knowledge bases and connectors.

The client signs in with either a personal access token or an OAuth 2.0 access token (see Authentication). It connects to PipesHub Cloud (https://app.pipeshub.com) by default. For a self-hosted instance, pass server_url="https://<your-instance>/api/v1" (see Server Selection).

Table of Contents

SDK Installation

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

uv

uv is a fast Python package installer and resolver, designed as a drop-in replacement for pip and pip-tools. It's recommended for its speed and modern Python tooling capabilities.

uv add pipeshub-sdk

PIP

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

pip install pipeshub-sdk

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 pipeshub-sdk

Shell and script usage with uv

You can use this SDK in a Python shell with uv and the uvx command that comes with it like so:

uvx --from pipeshub-sdk python

It's also possible to write a standalone Python script without needing to set up a whole project like so:

#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.10"
# dependencies = [
#     "pipeshub-sdk",
# ]
# ///

from pipeshub_sdk import Pipeshub

sdk = Pipeshub(
  # SDK arguments
)

# Rest of script here...

Once that is saved to a file, you can run it with uv run script.py where script.py can be replaced with the actual file name.

SDK Example Usage

Retrieve passages with citations

# Synchronous Example
import os
from pipeshub_sdk import Pipeshub, models


with Pipeshub(
    security=models.Security(
        bearer_auth=os.getenv("PIPESHUB_BEARER_AUTH", ""),
    ),
) as pipeshub:

    res = pipeshub.semantic_search.retrieve(query="how do we roll back a canary?", limit=8, rewrite_query=False)

    # Handle response
    print(res)

The same SDK client can also be used to make asynchronous requests by importing asyncio.

# Asynchronous Example
import asyncio
import os
from pipeshub_sdk import Pipeshub, models

async def main():

    async with Pipeshub(
        security=models.Security(
            bearer_auth=os.getenv("PIPESHUB_BEARER_AUTH", ""),
        ),
    ) as pipeshub:

        res = await pipeshub.semantic_search.retrieve_async(query="how do we roll back a canary?", limit=8, rewrite_query=False)

        # Handle response
        print(res)

asyncio.run(main())

Retrieval for RAG and agent frameworks

semantic_search.retrieve returns permission-filtered passages ("chunks"), each with its record and a citation link. It stores no search history, so you can call it on every request your application serves. See the Retrieval API docs.

Ready-made retrievers ship as extras:

pip install "pipeshub-sdk[langchain]"    # pipeshub_sdk.integrations.langchain.PipesHubRetriever
pip install "pipeshub-sdk[llamaindex]"   # pipeshub_sdk.integrations.llamaindex.PipesHubRetriever
from pipeshub_sdk import Pipeshub, models
from pipeshub_sdk.integrations.langchain import PipesHubRetriever

with Pipeshub(server_url="https://your-pipeshub-instance.com/api/v1",
              security=models.Security(bearer_auth="phpat_...")) as client:
    docs = PipesHubRetriever(client=client, limit=5).invoke("How do we roll back a canary deploy?")

Each result carries the chunk text and, in its metadata, the record (recordId, name, connector, mimeType, updatedAt), the citation (url, recordUrl, pageNum, blockIndex) and score. Both retrievers take limit, filters, max_chunks_per_record and rewrite_query, and support async. Examples: examples/retrievers/.

Authentication

Per-Client Security Schemes

This SDK supports the following security schemes globally:

Name Type Scheme Environment Variable
bearer_auth http HTTP Bearer PIPESHUB_BEARER_AUTH
oauth2 oauth2 OAuth2 token PIPESHUB_OAUTH2

You can set the security parameters through the security optional parameter when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:

import os
from pipeshub_sdk import Pipeshub, models


with Pipeshub(
    security=models.Security(
        bearer_auth=os.getenv("PIPESHUB_BEARER_AUTH", ""),
    ),
) as pipeshub:

    res = pipeshub.o_auth_provider.oauth_token(grant_type="client_credentials")

    # Handle response
    print(res)

Per-Operation Security Schemes

Some operations in this SDK require the security scheme to be specified at the request level. For example:

import os
from pipeshub_sdk import Pipeshub, models


with Pipeshub() as pipeshub:

    res = pipeshub.user_account.refresh_token(security=models.RefreshTokenSecurity(
        scoped_token=os.getenv("PIPESHUB_SCOPED_TOKEN", ""),
    ))

    # Handle response
    print(res)

Server-sent event streaming

Server-sent events are used to stream content from certain operations. These operations will expose the stream as Generator that can be consumed using a simple for loop. The loop will terminate when the server no longer has any events to send and closes the underlying connection.

The stream is also a Context Manager and can be used with the with statement and will close the underlying connection when the context is exited.

import os
from pipeshub_sdk import Pipeshub, models


with Pipeshub(
    security=models.Security(
        bearer_auth=os.getenv("PIPESHUB_BEARER_AUTH", ""),
    ),
) as pipeshub:

    res = pipeshub.knowledge_base.upload_records(kb_id="<id>", files=[], files_metadata=[
        {
            "file_path": "/docs/report.pdf",
            "last_modified": 2024.0,
        },
    ], is_versioned="true", record_type="FILE")

    with res as event_stream:
        for event in event_stream:
            # handle event
            print(event, flush=True)

File uploads

Certain SDK methods accept file objects as part of a request body or multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.

import os
from pipeshub_sdk import Pipeshub, models


with Pipeshub(
    security=models.Security(
        bearer_auth=os.getenv("PIPESHUB_BEARER_AUTH", ""),
    ),
) as pipeshub:

    res = pipeshub.knowledge_base.update_record_multipart(record_id="<id>")

    # Handle response
    print(res)

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a RetryConfig object to the call:

from pipeshub_sdk import Pipeshub
from pipeshub_sdk.utils import BackoffStrategy, RetryConfig


with Pipeshub() as pipeshub:

    res = pipeshub.o_auth_provider.oauth_token(grant_type="client_credentials",
        RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))

    # Handle response
    print(res)

If you'd like to override the default retry strategy for all operations that support retries, you can use the retry_config optional parameter when initializing the SDK:

from pipeshub_sdk import Pipeshub
from pipeshub_sdk.utils import BackoffStrategy, RetryConfig


with Pipeshub(
    retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False),
) as pipeshub:

    res = pipeshub.o_auth_provider.oauth_token(grant_type="client_credentials")

    # Handle response
    print(res)

Error Handling

PipeshubError is the base class for all HTTP error responses. It has the following properties:

Property Type Description
err.message str Error message
err.status_code int HTTP response status code eg 404
err.headers httpx.Headers HTTP response headers
err.body str HTTP body. Can be empty string if no body is returned.
err.raw_response httpx.Response Raw HTTP response
err.data Optional. Some errors may contain structured data. See Error Classes.

Example

from pipeshub_sdk import Pipeshub, errors


with Pipeshub() as pipeshub:
    res = None
    try:

        res = pipeshub.o_auth_provider.oauth_token(grant_type="client_credentials")

        # Handle response
        print(res)


    except errors.PipeshubError as e:
        # The base class for HTTP error responses
        print(e.message)
        print(e.status_code)
        print(e.body)
        print(e.headers)
        print(e.raw_response)

        # Depending on the method different errors may be thrown
        if isinstance(e, errors.ErrorResponse):
            print(e.data.error)  # models.ErrorResponseError

Error Classes

Primary errors:

  • PipeshubError: The base class for HTTP error responses.
    • ErrorResponse: Standard error envelope returned by all errors routed through ErrorMiddleware. Applies to all BaseError subclasses including HttpError, ValidationError, and others. The code field is a machine-readable string identifying the error type (e.g. HTTP_UNAUTHORIZED, HTTP_NOT_FOUND, VALIDATION_ERROR, INTERNAL_ERROR). *
Less common errors (21)

Network errors:

Inherit from PipeshubError:

  • OAuthClientManagementRateLimitError: JSON body when OAuth client management routes exceed the per-minute rate limit (same limiter as other /oauth-clients/* routes). Status code 429. Applicable to 20 of 141 methods.*
  • ApplicationJSONErrorResponse: Standard JSON error envelope from ErrorMiddleware for BaseError subclasses (error.middleware.ts). Returned for most API 4xx errors (unauthorized, forbidden, not found, validation failures, etc.). Applicable to 17 of 141 methods.*
  • OAuthErrorResponse: OAuth 2.0 Error Response (RFC 6749 Section 5.2). Standard error format for OAuth endpoints. Applicable to 3 of 141 methods.*
  • RateLimitErrorResponse: Rate-limit error payload (shape differs from standard error responses). Status code 429. Applicable to 3 of 141 methods.*
  • LocalFsDesktopRefusalError: 409 body returned when a Local FS connector cannot sync because of its owner device. Status code 409. Applicable to 2 of 141 methods.*
  • BadRequestError: Error envelope for a failed request. Status code 400. Applicable to 1 of 141 methods.*
  • UnauthorizedError: Error envelope for a failed request. Status code 401. Applicable to 1 of 141 methods.*
  • OAuthBearerTokenError: Error body written by the OAuth bearer-token middleware (RFC 6750 Section 3.1) on routes that accept only an OAuth access token, such as GET /oauth2/userinfo. The same error, error_description and scope values are repeated in the WWW-Authenticate response header. This is not the standard ErrorResponse envelope: error is a string. Applicable to 1 of 141 methods.*
  • ForbiddenError: Error envelope for a failed request. Status code 403. Applicable to 1 of 141 methods.*
  • StreamRecordErrorResponse: Error payload returned by the legacy record-stream proxy when the downstream streaming request fails after route middleware has passed. Applicable to 1 of 141 methods.*
  • GetKnowledgeHubRootNodesUnprocessableEntityError: Either of: - A typed query parameter could not be read: page or limit is not an integer or is out of range (page below 1, limit outside 1-200), onlyContainers or flattened is not a boolean, or page/limit was sent more than once. error.message is the connector service's own validation text. - A listing that spans a whole connector (a flattened listing, a search or a filter) was too large for the database to hold in memory, so it was refused instead of cut short. No page is returned. Open a folder (GET /knowledgeBase/knowledge-hub/nodes/{parentType}/{parentId}) to see its records, or add a search (q), which keeps only matching records in memory. Choosing a connector, or a filter that keeps most records (such as nodeTypes), does not help. Sorting by name with no filters is served from stored visibility where the connector allows it and is not affected. Status code 422. Applicable to 1 of 141 methods.*
  • GetKnowledgeHubChildNodesUnprocessableEntityError: Either of: - A typed query parameter could not be read: page or limit is not an integer or is out of range (page below 1, limit outside 1-200), or onlyContainers or flattened is not a boolean. error.message is the connector service's own validation text. - A listing that spans a whole connector (a flattened listing, a search or a filter) was too large for the database to hold in memory, so it was refused instead of cut short. No page is returned. Open a folder (GET /knowledgeBase/knowledge-hub/nodes/{parentType}/{parentId}) to see its records, or add a search (q), which keeps only matching records in memory. Choosing a connector, or a filter that keeps most records (such as nodeTypes), does not help. Sorting by name with no filters is served from stored visibility where the connector allows it and is not affected. Status code 422. Applicable to 1 of 141 methods.*
  • UploadAgentConversationChatAttachmentsUnprocessableEntityError: A PDF that could not be read within the upload's 50-second budget, or whose parse ran out of memory, is not attached (<name> is too large or complex to read right now, so it wasn't attached. ...). Only that upload fails. Status code 422. Applicable to 1 of 141 methods.*
  • SearchHistoryInternalServerError: Error envelope for a failed request. Status code 500. Applicable to 1 of 141 methods.*
  • GetKnowledgeHubRootNodesServiceUnavailableError: The database could not give this listing the memory it needs right now, because other requests were using it (nothing is wrong with the request). Retry after Retry-After seconds; the web app retries by itself. The body is the gateway's own busy message, not the service's wording. Status code 503. Applicable to 1 of 141 methods.*
  • GetKnowledgeHubChildNodesServiceUnavailableError: The database could not give this listing the memory it needs right now, because other requests were using it (nothing is wrong with the request). Retry after Retry-After seconds; the web app retries by itself. The body is the gateway's own busy message, not the service's wording. Status code 503. Applicable to 1 of 141 methods.*
  • ResponseValidationError: Type mismatch between the response data and the expected Pydantic model. Provides access to the Pydantic validation error via the cause attribute.

* Check the method documentation to see if the error is applicable.

Server Selection

Select Server by Index

You can override the default server globally by passing a server index to the server_idx: int optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

# Server Variables Description
0 https://{instance_url}/api/v1 instance_url Base API URL
1 https://{instance_url} instance_url Root URL (used for MCP endpoints mounted at /mcp)

If the selected server has variables, you may override its default values through the additional parameters made available in the SDK constructor:

Variable Parameter Default Description
instance_url instance_url: str "app.pipeshub.com" Host name, with an optional port, of a PipesHub instance served over HTTPS. For a plain-HTTP instance, such as a local one, set the full server URL instead.

Example

from pipeshub_sdk import Pipeshub


with Pipeshub(
    server_idx=0,
    instance_url="app.pipeshub.com",
) as pipeshub:

    res = pipeshub.o_auth_provider.oauth_token(grant_type="client_credentials")

    # Handle response
    print(res)

Override Server URL Per-Client

The default server can also be overridden globally by passing a URL to the server_url: str optional parameter when initializing the SDK client instance. For example:

from pipeshub_sdk import Pipeshub


with Pipeshub(
    server_url="https://app.pipeshub.com",
) as pipeshub:

    res = pipeshub.o_auth_provider.oauth_token(grant_type="client_credentials")

    # Handle response
    print(res)

Custom HTTP Client

The Python SDK makes API calls using the httpx HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with your own HTTP client instance. Depending on whether you are using the sync or async version of the SDK, you can pass an instance of HttpClient or AsyncHttpClient respectively, which are Protocol's ensuring that the client has the necessary methods to make API calls. This allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of httpx.Client or httpx.AsyncClient directly.

For example, you could specify a header for every request that this sdk makes as follows:

from pipeshub_sdk import Pipeshub
import httpx

http_client = httpx.Client(headers={"x-custom-header": "someValue"})
s = Pipeshub(client=http_client)

or you could wrap the client with your own custom logic:

from pipeshub_sdk import Pipeshub
from pipeshub_sdk.httpclient import AsyncHttpClient
import httpx

class CustomClient(AsyncHttpClient):
    client: AsyncHttpClient

    def __init__(self, client: AsyncHttpClient):
        self.client = client

    async def send(
        self,
        request: httpx.Request,
        *,
        stream: bool = False,
        auth: Union[
            httpx._types.AuthTypes, httpx._client.UseClientDefault, None
        ] = httpx.USE_CLIENT_DEFAULT,
        follow_redirects: Union[
            bool, httpx._client.UseClientDefault
        ] = httpx.USE_CLIENT_DEFAULT,
    ) -> httpx.Response:
        request.headers["Client-Level-Header"] = "added by client"

        return await self.client.send(
            request, stream=stream, auth=auth, follow_redirects=follow_redirects
        )

    def build_request(
        self,
        method: str,
        url: httpx._types.URLTypes,
        *,
        content: Optional[httpx._types.RequestContent] = None,
        data: Optional[httpx._types.RequestData] = None,
        files: Optional[httpx._types.RequestFiles] = None,
        json: Optional[Any] = None,
        params: Optional[httpx._types.QueryParamTypes] = None,
        headers: Optional[httpx._types.HeaderTypes] = None,
        cookies: Optional[httpx._types.CookieTypes] = None,
        timeout: Union[
            httpx._types.TimeoutTypes, httpx._client.UseClientDefault
        ] = httpx.USE_CLIENT_DEFAULT,
        extensions: Optional[httpx._types.RequestExtensions] = None,
    ) -> httpx.Request:
        return self.client.build_request(
            method,
            url,
            content=content,
            data=data,
            files=files,
            json=json,
            params=params,
            headers=headers,
            cookies=cookies,
            timeout=timeout,
            extensions=extensions,
        )

s = Pipeshub(async_client=CustomClient(httpx.AsyncClient()))

httpx2 (Pydantic's httpx fork)

httpx2 is Pydantic's maintained fork of httpx. To run this SDK on httpx2, call alias_httpx() at your program's entry point, before importing the SDK, so every import httpx — including the ones inside the SDK — resolves to httpx2:

import httpx2

httpx2.alias_httpx()

from pipeshub_sdk import Pipeshub

s = Pipeshub()

An SDK can also be generated against httpx2 directly, so it depends on the fork instead of httpx, by setting python.httpClientLibrary: httpx2 in gen.yaml.

Resource Management

The Pipeshub class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a context manager and reuse it across the application.

import os
from pipeshub_sdk import Pipeshub, models
def main():

    with Pipeshub(
        security=models.Security(
            bearer_auth=os.getenv("PIPESHUB_BEARER_AUTH", ""),
        ),
    ) as pipeshub:
        # Rest of application here...


# Or when using async:
async def amain():

    async with Pipeshub(
        security=models.Security(
            bearer_auth=os.getenv("PIPESHUB_BEARER_AUTH", ""),
        ),
    ) as pipeshub:
        # Rest of application here...

Debugging

You can setup your SDK to emit debug logs for SDK requests and responses.

You can pass your own logger class directly into your SDK.

from pipeshub_sdk import Pipeshub
import logging

logging.basicConfig(level=logging.DEBUG)
s = Pipeshub(debug_logger=logging.getLogger("pipeshub_sdk"))

You can also enable a default debug logger by setting an environment variable PIPESHUB_DEBUG to true.

IDE Support

PyCharm

Generally, the SDK will work well with most IDEs out of the box. However, when using PyCharm, you can enjoy much better integration with Pydantic by installing an additional plugin.

Available Resources and Operations

Available methods

Agents

AIModelsProviders

Connector

ConnectorConfiguration

ConnectorControl

ConnectorFilters

ConnectorInstances

ConnectorOAuth

ConnectorRegistry

Conversations

KnowledgeBase

KnowledgeHub

OAuthApps

OAuthConfiguration

OAuthProvider

OpenIDConnect

OrganizationAuthConfig

Organizations

PersonalAccessTokens

SemanticSearch

UserAccount

WebSearch

Support

Contributing

Most of this SDK is generated, so direct changes to generated files are overwritten by the next release. Please open an issue instead. See CONTRIBUTING.md.

License

Licensed under the Apache License 2.0.

Metadata

Release files for pipeshub-sdk 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pipeshub-sdk 2.0.1
File Size Uploaded Provenance Actions
pipeshub_sdk-2.0.1.tar.gz 527.9 kB Without provenance Details for pipeshub_sdk-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pipeshub-sdk 2.0.1
File Interpreter ABI Platform Actions
pipeshub_sdk-2.0.1-py3-none-any.whl Python 3 none any Details for pipeshub_sdk-2.0.1-py3-none-any.whl

Total release size: 1.3 MB

Release files / pipeshub_sdk-2.0.1.tar.gz

Download URL pipeshub_sdk-2.0.1.tar.gz
Size 527.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8f6b166cdaa845cbdab27e6e060c016ee15e18da2c07b36b568abbb94c01e755
BLAKE2b-256 checksum
How to use checksums
c678c88924a240ea6e58c74f002e170f434db85b7ec51b2744b5ae5432e3c9a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pipeshub_sdk-2.0.1-py3-none-any.whl

Download URL pipeshub_sdk-2.0.1-py3-none-any.whl
Size 810.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cdd1b781f32a205eae9a01104beec76ed452f3802cd4a3936420a76a60a71698
BLAKE2b-256 checksum
How to use checksums
df9c6f23057090523cf1c46b78e0798d42337845a3a53e7852daa6d0ad8a7d1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pipeshub-sdk 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page