segram.utils.resources module
Utilities for accessing package resources.
- class segram.utils.resources.Resource(path: str | bytes | PathLike, *, compression: Literal['.gz', '.bz2', '.xz'] | None = None)[source]
Bases:
objectResource handler class.
- path
Path to the resource file.
- compression
Compression being used. Deduced from the filename extension if not specified directly.
- classmethod from_package(package: str, filename: str) Self[source]
Construct from a package/filename specification.
- Parameters:
package – Package/module name using standard dot notation.
filename – Name of the resource file. Compression extension can be omitted. However, if it is specified then only files with a given extension are considered.
- static get_path(package: str, filename: str | bytes | PathLike) PathLike[source]
Get file path from package and file names.
- open(path: PathLike, mode: str, **kwds: Any) Any[source]
Open resource file.
- Parameters:
path – File path.
mode – File opening mode.
**kwds – Other keyword arguments passed to an appropriate
openfunction depending on the compression method.
- class segram.utils.resources.JSONResource(path: str | bytes | PathLike, *, compression: Literal['.gz', '.bz2', '.xz'] | None = None)[source]
Bases:
ResourceJSON resource handler class.
See also
Resourcebase resource accessor class.
- get(*, json_kws: Mapping | None = None, **kwds: Any) dict | list[source]
Get JSON resource.
- Parameters:
json_kws – Dictionary with keyword arguments passed to
json.loads().**kwds – Passed to
Resource.get().
- class segram.utils.resources.JSONLinesResource(path: str | bytes | PathLike, *, compression: Literal['.gz', '.bz2', '.xz'] | None = None)[source]
Bases:
JSONResourceJSON lines resource handler class.
See also
JSONResourceJSON resource handler.
- iter(*, json_kws: Mapping | None, **kwds: Any) Iterable[str | list | dict][source]
Get resource data line by line.
- Parameters:
json_kws – Dictionary with keyword arguments passed to
json.loads().**kwds – Passed to
Resource.get().
- get(*, json_kws: Mapping | None, **kwds: Any) Iterable[str | list | dict][source]
Get resource data line by line.
- Parameters:
json_kws – Dictionary with keyword arguments passed to
json.loads().**kwds – Passed to
Resource.get().