No project description provided
Project description
pyclsload
Lightweight helpers to load classes from Python source files and directories with sensible defaults, clear errors, and a tiny CLI.
Why
Avoid repeating the importlib boilerplate when you just want a class from a .py file:
from pathlib import Path
from pyclsload import load_cls
inst = load_cls(Path("somefile.py"), "MyClass", foo=1, bar=2)
print(inst)
Features
- Load a class from a file with
load_cls(path, name, *args, **kwargs) - Load all classes defined in a directory with
load_dir(directory, arguments=None, on_collision=...)- Only
*.pyfiles, skips files starting with_(like__init__.py) - Deterministic ordering (lexicographic by filename)
- Per-class kwargs via the
argumentsmapping - Collision policy:
overwrite(default),keep_first, orerror
- Only
- Helpful errors (
FileNotFoundError,ModuleLoadError,ClassNotFoundError) - Simple in-process cache to avoid re-executing the same file repeatedly
- Small CLI to try things out quickly
Usage
Load a single class
from pathlib import Path
from pyclsload import load_cls
inst = load_cls(Path("plugins/example.py"), "Plugin", answer=42)
print(inst)
Load a directory of classes
from pathlib import Path
from pyclsload import load_dir
instances = load_dir(Path("plugins"), {
"Example": {"answer": 42},
})
print(instances["Example"]) # -> Plugin instance
CLI
Install the package and run:
python -m pyclsload -f path/to/file.py -c ClassName -m run -fa x=1 y=2
Or list and instantiate all classes from a directory:
python -m pyclsload -d path/to/dir
Notes:
--class-argumentsand--function-argumentsaccept space-separated tokens. Usekey=valuefor kwargs; tokens without=are passed as positional strings.
Safety
Executing arbitrary Python files will execute code at import time. Only load trusted code.
Install
pip install pyclsload
See the tests for usage examples.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyclsload-1.6.0.tar.gz.
File metadata
- Download URL: pyclsload-1.6.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10c438354ef3e38c3434015ef5e32e6b92a1dde6050871c384aa665c08e022c6
|
|
| MD5 |
c87f01a3587f9c709ab5248f114c16f2
|
|
| BLAKE2b-256 |
013c00a01df6719880c8b14e85da09a5cee06bf0bc586d49a0851bbcbfcb88f9
|
Provenance
The following attestation bundles were made for pyclsload-1.6.0.tar.gz:
Publisher:
publish.yml on nbdy/pyclsload
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyclsload-1.6.0.tar.gz -
Subject digest:
10c438354ef3e38c3434015ef5e32e6b92a1dde6050871c384aa665c08e022c6 - Sigstore transparency entry: 630384193
- Sigstore integration time:
-
Permalink:
nbdy/pyclsload@564a93037296a68928f9500cc8f0d00937ec3a45 -
Branch / Tag:
refs/tags/v1.6.0 - Owner: https://github.com/nbdy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@564a93037296a68928f9500cc8f0d00937ec3a45 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyclsload-1.6.0-py3-none-any.whl.
File metadata
- Download URL: pyclsload-1.6.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f02a5ffcfca19240afdd57c1ebf34edec9d9679d686e15b593f7fb03d385c831
|
|
| MD5 |
18f4e98949b999dd5585ef5570eae0f2
|
|
| BLAKE2b-256 |
ca46f0186ddb03da1cee055a5041d1f75c7f9f965c30569595e0a876b5f8e64f
|
Provenance
The following attestation bundles were made for pyclsload-1.6.0-py3-none-any.whl:
Publisher:
publish.yml on nbdy/pyclsload
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyclsload-1.6.0-py3-none-any.whl -
Subject digest:
f02a5ffcfca19240afdd57c1ebf34edec9d9679d686e15b593f7fb03d385c831 - Sigstore transparency entry: 630384199
- Sigstore integration time:
-
Permalink:
nbdy/pyclsload@564a93037296a68928f9500cc8f0d00937ec3a45 -
Branch / Tag:
refs/tags/v1.6.0 - Owner: https://github.com/nbdy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@564a93037296a68928f9500cc8f0d00937ec3a45 -
Trigger Event:
push
-
Statement type: