Skip to main content

PoliWrap

A lightweight, framework-agnostic wrapper for reinforcement learning policy inference.

Installation

pip install poliwrap            # core only (numpy)
pip install poliwrap[onnx]      # + ONNX Runtime backend (CPU)
pip install poliwrap[onnx-gpu]  # + ONNX Runtime backend (CUDA)
pip install poliwrap[torch]     # + PyTorch backend
pip install poliwrap[all]       # all backends (CPU ONNX)

Each wrapper is importable only when its backend is installed.

Usage

ONNX

from poliwrap import ONNXPolicyWrapper

policy = ONNXPolicyWrapper("policy.onnx")
actions = policy({"actor_obs": obs})  # obs: dict[str, np.ndarray]

PyTorch

from poliwrap import TorchPolicyWrapper

policy = TorchPolicyWrapper("policy.pt")
actions = policy({"actor_obs": obs})  # obs: dict[str, torch.Tensor]

Extending

PolicyWrapper is generic over observation and action types. File-backed implementations can inherit from FilePolicyWrapper, which provides a model_path:

from pathlib import Path

import numpy as np

from poliwrap import FilePolicyWrapper


class MyPolicyWrapper(FilePolicyWrapper[dict[str, np.ndarray], np.ndarray]):
    def __init__(self, model_path: str | Path) -> None:
        super().__init__(model_path)
        self._load_model()

    def _load_model(self) -> None:
        self.model = ...  # load from self.model_path

    def __call__(self, observations: dict[str, np.ndarray]) -> np.ndarray:
        return self.model(observations)

PolicyWrapper has no path requirement, so policies backed by other sources can subclass it directly. Both base classes provide preprocess_observations, postprocess_actions, and reset hooks.

License

MIT

Metadata

Release files for poliwrap 0.0.9

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

Source distribution (sdist)

Source distribution for poliwrap 0.0.9
File Size Uploaded
poliwrap-0.0.9.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for poliwrap 0.0.9
File Interpreter ABI Platform
poliwrap-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / poliwrap-0.0.9.tar.gz

Download URL poliwrap-0.0.9.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b0b6c3780a127d7ab0c8564b3ba950e5b8342cedbc1c665912eb9d1986ce1d42
BLAKE2b-256 checksum
How to use checksums
b857c1f66df1d38b8648278108498bb3c80f378d1bb3c899cb4239979293f2a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.22 {"installer":{"name":"uv","version":"0.11.22","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":null}

Release files / poliwrap-0.0.9-py3-none-any.whl

Download URL poliwrap-0.0.9-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34179537f270cb467e58301dac74f5513ca0657f295f7da0b46712e3018a99c8
BLAKE2b-256 checksum
How to use checksums
005619323a619d7e5e4dc1c8be2d090c7899f457335dcd7d819f2764bf275b67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.22 {"installer":{"name":"uv","version":"0.11.22","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":null}

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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