lit-sb3
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 oflightning.Trainer - Environment management through
RLEnvDataModule, aLightningDataModulefor 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
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)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| lit_sb3-0.0.1.tar.gz | 260.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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.