Skip to content

Registry

Exported from sekai and sekai.registry. See the Registry guide.

Functions

register

register(id: str, entry_point: str | Callable[..., Any], **kwargs: Any) -> EnvSpec

Register an environment with the global registry.

make

make(id: str | EnvSpec, *, max_episode_steps: int | None = None, **kwargs: Any) -> Any

Create an environment by ID (or EnvSpec) from the global registry.

Keyword arguments are forwarded to the environment's constructor, overriding the kwargs it was registered with. max_episode_steps overrides the registered time limit (it is not passed to the constructor); -1 removes it.

make_vec

make_vec(id: str | EnvSpec, num_envs: int = 1, *, vectorization_mode: VectorizationMode | None = None, vector_kwargs: dict[str, Any] | None = None, wrappers: Sequence[Callable[[Any], Any]] = (), **env_kwargs: Any) -> Any

Create a vectorised environment of num_envs copies of a registered env.

Parameters:

Name Type Description Default
id str | EnvSpec

Registered environment ID or EnvSpec.

required
num_envs int

Number of sub-environments.

1
vectorization_mode VectorizationMode | None

"native" (the env's own batched implementation, its registered vector_entry_point; "vector_entry_point" is an alias), "sync" (SyncVecEnv), "async" (AsyncVecEnv, asyncio) or "proc" (ProcVecEnv, worker processes). None (the default) picks "native" when the env has one and no per-env wrappers apply (neither wrappers nor the spec's additional_wrappers), else "sync".

None
vector_kwargs dict[str, Any] | None

Extra keyword arguments for the VecEnv constructor (e.g. autoreset, or num_workers / shared_memory for "proc").

None
wrappers Sequence[Callable[[Any], Any]]

Callables applied in order to each sub-env, e.g. [lambda env: sekai.FlattenObservation(env)]. Not available with "native", which has no per-env objects (nor are the spec's additional_wrappers: "native" raises ValueError for either); use Vec* wrappers instead.

()
**env_kwargs Any

Forwarded to make() for every sub-env (or to the native implementation, which is called as factory(num_envs=..., **kwargs) and also receives max_episode_steps when there is a time limit). Each sub-env gets sampler.spawn() of an episode sampler (sampler=), so the sub-envs are independent copies of the env on every backend.

{}

spec

spec(id: str) -> EnvSpec

Retrieve an EnvSpec by ID from the global registry.

all_specs

all_specs() -> list[EnvSpec]

Return all registered environment specs.

deregister

deregister(id: str) -> None

Remove an environment from the global registry.

register_namespace

register_namespace(namespace: str, loader: Callable[[], Any]) -> None

Register a lazy namespace loader on the global registry.

pprint_registry

pprint_registry() -> None

Print all registered environments, grouped by namespace.

Specs

EnvSpec dataclass

EnvSpec(id: str, entry_point: str | Callable[..., Any] | None = None, reward_threshold: float | None = None, nondeterministic: bool = False, max_episode_steps: int | None = None, kwargs: dict[str, Any] = dict(), additional_wrappers: tuple[WrapperSpec, ...] = tuple(), vector_entry_point: str | Callable[..., Any] | None = None)

Serialisable environment specification.

IDs follow the format: [namespace/]Name[-vN] Examples: "CartPole-v1", "qc/MarketEnv-v0", "my_ns/CustomEnv"

vector_entry_point optionally names a natively vectorised implementation (a VecEnv taking num_envs plus the env's kwargs) that make_vec() uses by default.

make

make(**kwargs: Any) -> Any

Instantiate this environment.

to_json

to_json() -> str

Serialise to JSON. Callable entry points cannot be serialised and are dropped.

pprint

pprint() -> str

Human-readable multi-line description of this spec.

WrapperSpec dataclass

WrapperSpec(name: str, entry_point: str, kwargs: dict[str, Any] = dict())

Specification for a wrapper to apply on top of an environment.

The registry class

The functions above operate on a module-level EnvRegistry; create your own instance for an isolated registry (for example in tests).

EnvRegistry

EnvRegistry()

Registry mapping env IDs to EnvSpec objects.

Supports lazy namespace loading via register_namespace() — useful for plugin packages that ship environments without importing at startup.

deregister

deregister(id: str) -> None

Remove an environment from the registry.

register_namespace

register_namespace(namespace: str, loader: Callable[[], Any]) -> None

Register a lazy loader for an entire namespace.

The loader is called once when any env from that namespace is first requested. This enables plugin packages to defer imports until needed.

Example
sekai.register_namespace("qc", lambda: import_module("qiancapital.envs"))