Skip to main content

lit-sb3

Build Documentation

Docs with MkDocs uv linting: ruff ty prek security: bandit Semantic Versions Copier SPEC 0 — Minimum Supported Dependencies License

lit-sb3 is a PyTorch Lightning adaptation of Stable-Baselines3. It preserves the familiar SB3 algorithm API where practical, while moving training orchestration into Lightning so reinforcement learning runs can use Lightning callbacks, loggers, checkpointing, precision settings, and distributed strategies.

Features

  • Stable-Baselines3-style reinforcement learning algorithms implemented on top of PyTorch Lightning
  • Lightning-native training through RLTrainer, a subclass of lightning.Trainer
  • Environment management through RLEnvDataModule, a LightningDataModule for RL stages
  • Backwards-friendly model.learn(total_timesteps=..., env=...) shim for quick starts
  • Support for Lightning callbacks, loggers, checkpointing, mixed precision, and accelerator strategies
  • Notebook-friendly workflows, MkDocs documentation, and example notebooks in this repository

Installation

With pip:

python -m pip install lit-sb3

With uv:

uv add lit-sb3

Optional extras are available for specific workflows and environment families:

uv add lit-sb3[hub,opt,viz,atari,box2d,classic-control,mujoco,toy-text]

How to use it

Most of the library keeps the familiar sklearn-like style used by Stable-Baselines3.

Here is a quick example of how to train and run PPO on a cartpole environment:

import gymnasium as gym

from lit_sb3 import PPO

env = gym.make("CartPole-v1", render_mode="human")

model = PPO("MlpPolicy", verbose=1)
model.learn(total_timesteps=10_000, env=env) # env needs to be passed here instead of algorithm

vec_env = model.get_env()
obs = vec_env.reset()
for _ in range(1000):
    action, _states = model.predict(obs, deterministic=True)
    obs, reward, done, info = vec_env.step(action)
    vec_env.render()
    # VecEnv resets automatically
    # if done:
    #   obs = env.reset()

env.close()

Lightning-native workflow

The preferred interface for anything beyond a minimal example is the Lightning-native workflow.

import gymnasium as gym

from lit_sb3 import PPO, RLEnvDataModule, RLTrainer

model = PPO("MlpPolicy")
datamodule = RLEnvDataModule(
    train_env=gym.make("CartPole-v1"),
    test_env=gym.make("CartPole-v1"),
)
trainer = RLTrainer(max_steps=10_000, run_name="ppo_cartpole")

trainer.fit(model, datamodule=datamodule)
trainer.test(model, datamodule=datamodule)

Docs

uv run mkdocs build -f ./mkdocs.yml -d ./_build/

Update template

copier update --trust -A --vcs-ref=HEAD

Credits

This project was generated with 🚀 python project template.

Metadata

Release files for lit-sb3 0.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 lit-sb3 0.0.1
File Size Uploaded Provenance
lit_sb3-0.0.1.tar.gz 260.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for lit-sb3 0.0.1
File Interpreter ABI Platform
lit_sb3-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 654.4 kB

Release files / lit_sb3-0.0.1.tar.gz

Download URL lit_sb3-0.0.1.tar.gz
Size 260.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c778fe48cf53b923efd51f1903ece344dc949b106ce9f3fe74892ad4bbcd7512
BLAKE2b-256 checksum
How to use checksums
c21005ba93a6bcf8c6c3349ea268df3732dffc76f5496477d72f455eadcab4ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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 / lit_sb3-0.0.1-py3-none-any.whl

Download URL lit_sb3-0.0.1-py3-none-any.whl
Size 393.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfd7c5ffc01de7e1ce174365a334053ec5449434bf9cc463a2a2f39963245f7a
BLAKE2b-256 checksum
How to use checksums
08b47a99f5e1f3f60c27fc2ac154d0181f796d05801c42ff97b7c4487d374f8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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 lit-sb3 0.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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

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