Skip to main content

InOrbit Edge SDK for Python

Project description

InOrbit Python Edge SDK

Build License PyPI - Package Version PyPI - Python Version

The InOrbit Edge SDK allows Python programs to communicate with InOrbit platform on behalf of robots - providing robot data and handling robot actions. Its goal is to ease the integration between InOrbit and any other software that handles robot data.


Features

  • Robot session handling through a RobotSessionPool.
  • Publish key-values.
  • Publish robot poses.
  • Publish robot odometry.
  • Publish robot path.
  • Publish robot laser.
  • Execute callbacks on Custom Action execution.
  • Execute scripts (or any program) in response to Custom Action execution.

Quick Start

from inorbit_edge.robot import RobotSessionFactory, RobotSessionPool


def my_command_handler(robot_id, command_name, args, options):
    """Callback for processing custom command calls.

    Args:
        robot_id (str): InOrbit robot ID
        command_name (str): InOrbit command e.g. 'customCommand'
        args (list): Command arguments
        options (dict): object that includes
            - `result_function` can be called to report command execution
            result with the following signature: `result_function(return_code)`
            - `progress_function` can be used to report command output with
            the following signature: `progress_function(output, error)`
            - `metadata` is reserved for the future and will contain additional
            information about the received command request.
    """
    if command_name == "customCommand":
        print(f"Received '{command_name}' for robot '{robot_id}'!. {args}")
        # Return '0' for success
        options["result_function"]("0")


robot_session_factory = RobotSessionFactory(
    api_key="<YOUR_API_KEY>"
)

# Register commands handlers. Note that all handlers are invoked.
robot_session_factory.register_command_callback(my_command_handler)
robot_session_factory.register_commands_path("./user_scripts", r".*\.sh")

robot_session_pool = RobotSessionPool(robot_session_factory)

robot_session = robot_session_pool.get_session(
    robot_id="my_robot_id_123", robot_name="Python SDK Quick Start Robot"
)

robot_session.publish_pose(x=0.0, y=0.0, yaw=0.0)

Installation

Stable Release: pip install inorbit-edge

Development Head: pip install git+https://github.com/inorbit-ai/edge-sdk-python.git

Documentation

For full package documentation please visit InOrbit Developer Portal.

Development

See CONTRIBUTING.md for information related to developing the code.

The Three Commands You Need To Know

  1. pip install -e .[dev]

    This will install your package in editable mode with all the required development dependencies (i.e. tox).

  2. make build

    This will run tox which will run all your tests in Python 3.10 - 3.13 as well as linting your code.

  3. make clean

    This will clean up various Python and build generated files so that you can ensure that you are working in a clean environment.

Metrics

The SDK is capable of collecting internal metrics such as number of calls to publishing functions. It uses OpenTelemetry, which supports various exporting mechanisms. Connectors are responsible for configuring the exporter of their choice; as well as adding more metrics if they chose to do so.

Install the optional telemetry extra (see requirements-telemetry.txt) so the SDK records real OpenTelemetry metrics. Without it, built-in metrics are no-ops and the base package has no OpenTelemetry dependency:

pip install inorbit-edge[telemetry]

To export to Prometheus, the extra above includes opentelemetry-exporter-prometheus and prometheus-client. The following is an example initialization code that enables a Prometheus HTTP endpoint, where all SDK metrics (including system metrics such as CPU usage) and any metric added by the connector can be scraped and exported to any external system (Grafana, StackDriver, etc.)

from inorbit_edge.metrics import setup_prometheus_meter_provider
from prometheus_client import start_http_server

# ...

if setup_prometheus_meter_provider(
    service_name="my-connector",
    service_instance_id="robot-123",
    service_version="1.2.3",
):
    start_http_server(port=9464, addr="0.0.0.0")

Custom metrics can use the same meter provider. Define instruments once during module initialization, then record values where the connector does the work:

from inorbit_edge.metrics import get_meter

meter = get_meter("my_connector")
messages_processed_counter = meter.create_counter(
    "messages_processed",
    unit="1",
    description="Number of input messages processed by the connector",
)


def process_message(robot_id, message):
    # ... connector-specific processing ...
    messages_processed_counter.add(1, {"robot_id": robot_id})

When exported to Prometheus with service_name="my-connector", this appears as my_connector_messages_processed_total with a robot_id label. Without the telemetry extra installed, the same code is safe to run but records no data.

For call-count metrics, the SDK also provides a decorator. This keeps the increment close to the function being counted:

from inorbit_edge.metrics import get_meter, with_counter_metric

meter = get_meter("my_connector")
command_handler_counter = meter.create_counter(
    "command_handler_calls",
    unit="1",
    description="Number of command handler invocations",
)


@with_counter_metric(command_handler_counter, attributes={"command": "dock"})
def handle_dock_command(command_payload):
    # ... handle the command ...
    return "accepted"

If attributes depend on the function arguments, pass a callable instead of a static dictionary:

@with_counter_metric(
    command_handler_counter,
    attributes=lambda robot_id, command_payload: {"robot_id": robot_id},
)
def handle_command(robot_id, command_payload):
    # ... handle the command ...
    return "accepted"

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

inorbit_edge-3.1.0.tar.gz (45.9 kB view details)

Uploaded Source

Built Distribution

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

inorbit_edge-3.1.0-py3-none-any.whl (43.6 kB view details)

Uploaded Python 3

File details

Details for the file inorbit_edge-3.1.0.tar.gz.

File metadata

  • Download URL: inorbit_edge-3.1.0.tar.gz
  • Upload date:
  • Size: 45.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for inorbit_edge-3.1.0.tar.gz
Algorithm Hash digest
SHA256 8b4036c3cd288fb656ff399354c598185cc7043f8a481fc6430b92ef7f1350f6
MD5 a069f4f387eb69712b6e41121b802682
BLAKE2b-256 d1c59d6d21835ef57c943ad8f5c057c8a7ad7fb6056b90e6c6b0904b051aa39e

See more details on using hashes here.

File details

Details for the file inorbit_edge-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: inorbit_edge-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 43.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for inorbit_edge-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad073aa29a951de2837d20e3045279a72aa1d8ac48130144c9742e0912a75d01
MD5 03e4ee9bd501d629e3d5909fadcc52b9
BLAKE2b-256 b03d0ef724f3db575c5d70140ec04c492f183af0011c557187eb6d66effcdb4d

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