simvx.core.resource

Package-resource handle.

The :class:Resource class is the canonical Pythonic sugar for an asset that ships inside a Python package. It stores a (package, name) pair and resolves lazily through :mod:importlib.resources.

For raw filesystem assets, just pass a path string or :class:pathlib.Path directly to whichever loader you need (AudioStream, Mesh.from_obj, ResourceLoader, …). There are no URI schemes.

Examples::

from pathlib import Path
from simvx.core import AudioStream, Resource

AudioStream("music/theme.ogg")                 # filesystem
AudioStream(Path.home() / "music/theme.ogg")  # filesystem (PathLike)
AudioStream(Resource("game.assets", "hero.wav"))  # package resource

# The unwrapped importlib form also works:
import importlib.resources
AudioStream(importlib.resources.files("game.assets") / "hero.wav")

Module Contents

Classes

Resource

Lazy handle to a file shipped inside a Python package.

Data

log

API

simvx.core.resource.log

‘getLogger(…)’

class simvx.core.resource.Resource(package: str, name: str)[source]

Lazy handle to a file shipped inside a Python package.

Construction stores the package + filename without touching the filesystem; resolution happens on first access of :attr:path,

Meth:

read_bytes, or :meth:open.

Example::

>>> r = Resource("pkgres_demo", "marker.bin")
>>> r.read_bytes()
b'SIMVX_PKGRES_OK\n'

Initialization

__slots__

(‘package’, ‘name’)

property path: pathlib.Path[source]

Resolve to a filesystem :class:Path (strict; raises if missing).

read_bytes() bytes[source]

Read and return the resource as bytes.

open(mode: str = 'rb')[source]

Open the resource as a file. Defaults to binary read.

__repr__() str[source]
__eq__(other: object) bool[source]
__hash__() int[source]