Skip to main content

pyclsload

CodeFactor

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 *.py files, skips files starting with _ (like __init__.py)
    • Deterministic ordering (lexicographic by filename)
    • Per-class kwargs via the arguments mapping
    • Collision policy: overwrite (default), keep_first, or error
  • 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-arguments and --function-arguments accept space-separated tokens. Use key=value for 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.

Metadata

Release files for pyclsload 1.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyclsload 1.6.0
File Size Uploaded Provenance Actions
pyclsload-1.6.0.tar.gz 5.8 kB With provenance Details for pyclsload-1.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyclsload 1.6.0
File Interpreter ABI Platform Actions
pyclsload-1.6.0-py3-none-any.whl Python 3 none any Details for pyclsload-1.6.0-py3-none-any.whl

Total release size: 11.8 kB

Release files / pyclsload-1.6.0.tar.gz

Download URL pyclsload-1.6.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
10c438354ef3e38c3434015ef5e32e6b92a1dde6050871c384aa665c08e022c6
BLAKE2b-256 checksum
How to use checksums
013c00a01df6719880c8b14e85da09a5cee06bf0bc586d49a0851bbcbfcb88f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2025.

Transparency log

Release files / pyclsload-1.6.0-py3-none-any.whl

Download URL pyclsload-1.6.0-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f02a5ffcfca19240afdd57c1ebf34edec9d9679d686e15b593f7fb03d385c831
BLAKE2b-256 checksum
How to use checksums
ca46f0186ddb03da1cee055a5041d1f75c7f9f965c30569595e0a876b5f8e64f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2025.

Transparency log

Security for pyclsload 1.6.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyclsload-1.6.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2025.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page