CodeSampleX

Sample

lazy-loader 0.5: lazy_loader.attach, lazy_loader.load

Verified sample for pypi lazy-loader 0.5: lazy_loader.attach, lazy_loader.load. The contract ran on python 3.12 · linux alpine/x64 · docker and passed.

sha256:551009ab96721e8ce73aa65148534eca1ef64d353a48fa66899e018461809eef

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment python linux 24 · ubuntu · glibc 2.39 x64 python python pip

Verification-run environments

Environment Contract Stages Run
python 3.12 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1python:3.12-alpine@sha256:d09d15e60962…
2026-08-27

Case

HOW
Goal
verify pkg:pypi/lazy-loader@0.5
Packages
Symbols
  • lazy_loader.attach
  • lazy_loader.load
Environment
python
Created
2026-08-27T18:29:34Z

Contract

  1. lazy_loader.load creates a lazy proxy that imports the target module and accesses its attributes on first demand.
  2. lazy_loader.load raises ModuleNotFoundError on first attribute access when given a non-existent module name.
  3. lazy_loader.attach returns __getattr__, __dir__, and __all__ for configuring lazy-loading of submodules and submodule attributes in package __init__.
  4. lazy_loader.attach exposes configured submodules and exported symbols via __dir__ and __all__.
  5. lazy_loader.attach dynamically resolves submodule attributes and submodules on demand when accessed via the parent package.
  6. lazy_loader.attach raises AttributeError when attempting to access unconfigured attributes on the parent package.

Files

  • NOTES.md
  • PROMPT.md
  • csx.json
  • requirements.txt
  • sample_pkg/__init__.py
  • sample_pkg/calc.py
  • sample_pkg/greeter.py
  • spec.json
  • test/contract.py

Download the source artifact (tar.gz)

Source

NOTES.md
# lazy-loader load and attach APIs

This sample pins `lazy-loader` 0.5 and verifies `lazy_loader.load` and `lazy_loader.attach` for on-demand module and package attribute loading.

The contract verifies:
- `lazy_loader.load` returns a lazy module proxy that resolves module imports and attribute accesses on first use without eager overhead.
- `lazy_loader.load` raises `ModuleNotFoundError` on first attribute access when referencing a non-existent module name.
- `lazy_loader.attach` provides `(__getattr__, __dir__, __all__)` to configure top-level package laziness in `__init__.py`.
- `lazy_loader.attach` exposes configured submodules and exported symbols via `__dir__` and `__all__`.
- `lazy_loader.attach` dynamically resolves submodule functions, constants, and submodules upon access.
- `lazy_loader.attach` raises `AttributeError` when unconfigured attributes are accessed on the parent package.
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:pypi/lazy-loader@0.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:pypi/lazy-loader@0.5
Demonstrate these symbols/APIs:
  - lazy_loader.attach
  - lazy_loader.load

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:5da54b3c9bc90b02a0d7b45c2452aa97a60d4143a31abc0781f340e5b4396912","contract":["lazy_loader.load creates a lazy proxy that imports the target module and accesses its attributes on first demand.","lazy_loader.load raises ModuleNotFoundError on first attribute access when given a non-existent module name.","lazy_loader.attach returns __getattr__, __dir__, and __all__ for configuring lazy-loading of submodules and submodule attributes in package __init__.","lazy_loader.attach exposes configured submodules and exported symbols via __dir__ and __all__.","lazy_loader.attach dynamically resolves submodule attributes and submodules on demand when accessed via the parent package.","lazy_loader.attach raises AttributeError when attempting to access unconfigured attributes on the parent package."],"goal":"verify pkg:pypi/lazy-loader@0.5","kind":"HOW","packages":["pkg:pypi/lazy-loader@0.5"],"schemaVersion":1,"symbols":["lazy_loader.attach","lazy_loader.load"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"pypi","executionContext":"python","language":"python","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"pip","runtime":"python","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/lazy-loader@0.5"],"schemaVersion":1,"subject":"pkg:pypi/lazy-loader@0.5","symbols":["lazy_loader.attach","lazy_loader.load"],"verifierAdapter":"python@1"}
requirements.txt
lazy-loader==0.5
sample_pkg/__init__.py
import lazy_loader as lazy

__getattr__, __dir__, __all__ = lazy.attach(
    __name__,
    submodules=["calc", "greeter"],
    submod_attrs={
        "calc": ["add", "PI_APPROX"],
        "greeter": ["greet"],
    },
)
sample_pkg/calc.py
PI_APPROX = 3.14159

def add(a, b):
    return a + b
sample_pkg/greeter.py
def greet(name):
    return f"Hello, {name}!"
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:pypi/lazy-loader@0.5",
  "kind": "HOW",
  "packages": [
    "pkg:pypi/lazy-loader@0.5"
  ],
  "symbols": [
    "lazy_loader.attach",
    "lazy_loader.load"
  ]
}
test/contract.py
import os
import sys

# Ensure sample package directory is importable
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if BASE_DIR not in sys.path:
    sys.path.insert(0, BASE_DIR)

import lazy_loader as lazy

# 1. Verify lazy_loader.load creates a lazy proxy that imports the target module and accesses its attributes on first demand
math_proxy = lazy.load("math")
assert math_proxy.sqrt(25) == 5.0, "Expected lazy math.sqrt(25) to return 5.0"
assert math_proxy.pi > 3.14, "Expected lazy math.pi to be accessible"

try:
    _ = math_proxy.non_existent_attribute_xyz
    raise AssertionError("Expected AttributeError on non-existent attribute of loaded module")
except AttributeError:
    pass

# 2. Verify lazy_loader.load raises ModuleNotFoundError on first attribute access when given a non-existent module name
bad_proxy = lazy.load("non_existent_dummy_module_12345")
try:
    _ = bad_proxy.some_attribute
    raise AssertionError("Expected ModuleNotFoundError when accessing attribute on non-existent module")
except ModuleNotFoundError:
    pass

# 3. Verify lazy_loader.attach returns __getattr__, __dir__, and __all__ for package lazy-loading
import sample_pkg

# Check __all__
expected_all = {"calc", "greeter", "add", "PI_APPROX", "greet"}
assert set(sample_pkg.__all__) == expected_all, f"Expected __all__ to contain {expected_all}, got {sample_pkg.__all__}"

# 4. Verify lazy_loader.attach exposes configured submodules and exported symbols via __dir__
dir_entries = set(dir(sample_pkg))
for sym in ["calc", "greeter", "add", "PI_APPROX", "greet"]:
    assert sym in dir_entries, f"Expected {sym} in dir(sample_pkg)"

# 5. Verify lazy_loader.attach dynamically resolves submodule attributes and submodules on demand
assert sample_pkg.add(10, 20) == 30, "Expected sample_pkg.add(10, 20) == 30"
assert sample_pkg.PI_APPROX == 3.14159, "Expected sample_pkg.PI_APPROX == 3.14159"
assert sample_pkg.greet("Antigravity") == "Hello, Antigravity!", "Expected sample_pkg.greet to format string"
assert sample_pkg.calc.add(3, 4) == 7, "Expected sample_pkg.calc.add(3, 4) == 7"
assert sample_pkg.greeter.greet("CodeSampleX") == "Hello, CodeSampleX!"

# 6. Verify lazy_loader.attach raises AttributeError when accessing unconfigured attributes
try:
    _ = sample_pkg.unconfigured_function_abc
    raise AssertionError("Expected AttributeError for unconfigured attribute on sample_pkg")
except AttributeError:
    pass

print("CONTRACT PASS: lazy-loader attach and load verified offline")

Origin Seeder

anonymous