Skip to main content

Client for the XPipe API

Project description

XPipe Python API

GitHub license PyPI version

Python client for the XPipe API. This library is a wrapper for the raw HTTP API and intended to make working with it more convenient.

Installation

python3 -m pip install xpipe_api

Usage

from xpipe_api import Client

# By default, Client() will read an access key from the file xpipe_auth on the local filesystem
# and talk to the XPipe HTTP server on localhost.  To connect to a remote instance with an API
# key, use Client(token="foo", base_url = "http://servername:21721")
client = Client()

# connection_query accepts glob-based filters on the category, connection name, and connection type
all_connections = client.connection_query()

# Each connection includes uuid, category, connection, and type information
first_connection_uuid = all_connections[0]["uuid"]

# Before any shell commands can be run, a shell session must be started on a connection
client.shell_start(first_connection_uuid)

# Prints {'exitCode': 0, 'stdout': 'hello world', 'stderr': ''}
print(client.shell_exec(first_connection_uuid, "echo hello world"))

# Clean up after ourselves by stopping the shell session
client.shell_stop(first_connection_uuid)

There's also an async version of the client that can be accessed as AsyncClient:

import asyncio
from xpipe_api import AsyncClient


async def main():
    # By default, Client() will read an access key from the file xpipe_auth on the local filesystem
    # and talk to the XPipe HTTP server on localhost.  To connect to a remote instance with an API
    # key, use Client(token="foo", base_url = "http://servername:21721")
    client = AsyncClient()

    # connection_query accepts glob-based filters on the category, connection name, and connection type
    all_connections = await client.connection_query()

    # Each connection includes uuid, category, connection, and type information
    first_connection_uuid = all_connections[0]["uuid"]

    # Before any shell commands can be run, a shell session must be started on a connection
    await client.shell_start(first_connection_uuid)

    # Prints {'exitCode': 0, 'stdout': 'hello world', 'stderr': ''}
    print(await client.shell_exec(first_connection_uuid, "echo hello world"))

    # Clean up after ourselves by stopping the shell session
    await client.shell_stop(first_connection_uuid)


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

This is only a short summary of the library. You can find more supported functionalities in the source itself.

Tests

To run the test suite, you'll need to define the XPIPE_APIKEY env var. This will allow the two "log in with the ApiKey rather than Local method" tests to work. Here's the recommended method for running the tests with poetry:

cd /path/to/python_xpipe_api
poetry install
XPIPE_APIKEY=<api_key> poetry run pytest

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

xpipe_api-0.1.26.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

xpipe_api-0.1.26-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file xpipe_api-0.1.26.tar.gz.

File metadata

  • Download URL: xpipe_api-0.1.26.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Windows/10

File hashes

Hashes for xpipe_api-0.1.26.tar.gz
Algorithm Hash digest
SHA256 b515481eecf90158f56751e561b5df0fb71c80812ee8155294ce0e978f5a7488
MD5 984c927a6e5a800b9b8fa6ec08f702cb
BLAKE2b-256 f6d2062a4d050d131db6dd9d9a36ab9bb96ee6d83aac9c090637069c3eb96f63

See more details on using hashes here.

File details

Details for the file xpipe_api-0.1.26-py3-none-any.whl.

File metadata

  • Download URL: xpipe_api-0.1.26-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Windows/10

File hashes

Hashes for xpipe_api-0.1.26-py3-none-any.whl
Algorithm Hash digest
SHA256 c531166348c49986da826a2d4c1c1c965899a0723ff78f00033175fb7cd539c6
MD5 7f4851209ff0c14fe34f831bad2f8620
BLAKE2b-256 807abcd1fc6fea81759722f0e514aeb0f0ad28fab574d440ffb64e84f685112e

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