Sample
pyyaml 6.0.3: yaml
Verified sample for pypi pyyaml 6.0.3: yaml. The contract ran on python 3.12 · linux alpine/x64 · docker and passed: yaml.safe_load deserializes YAML strings…
sha256:b4259c280b636f8de9284a3e9f4febfdab001a064dfd8fde8a45619799d1fa66
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 yaml in pkg:pypi/pyyaml@6.0.3
- Packages
- Symbols
-
- yaml
- Environment
- python
- Created
- 2026-08-27T18:04:52Z
Contract
- yaml.safe_load deserializes YAML strings and file-like streams (io.StringIO) into native Python dictionaries, lists, booleans, and numbers.
- yaml.safe_dump serializes Python data structures to standard YAML with configurable formatting such as sort_keys and default_flow_style.
- yaml.safe_load_all and yaml.safe_dump_all handle multi-document YAML streams delimited by document separators (---).
- yaml.SafeLoader and yaml.SafeDumper support custom tag constructors and representers for domain-specific type serialization.
- yaml.safe_load raises yaml.YAMLError on malformed syntax and yaml.constructor.ConstructorError on unsafe arbitrary python object tags.
Files
- NOTES.md
- PROMPT.md
- csx.json
- requirements.txt
- spec.json
- test/contract.py
Source
# PyYAML core API
This sample pins `pyyaml` 6.0.3 and verifies core YAML serialization, deserialization, multi-document streaming, and safe extensibility using the `yaml` module.
The contract verifies:
- `yaml.safe_load` parses YAML strings and streams into native Python structures.
- `yaml.safe_dump` serializes Python objects to valid formatted YAML strings.
- `yaml.safe_load_all` and `yaml.safe_dump_all` parse and produce multi-document YAML streams.
- `yaml.SafeLoader` and `yaml.SafeDumper` support custom constructor and representer registrations for custom tags.
- Robust error handling: `yaml.YAMLError` on invalid syntax and `yaml.constructor.ConstructorError` on unsafe Python object tags.
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 yaml in pkg:pypi/pyyaml@6.0.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:pypi/pyyaml@6.0.3
Demonstrate these symbols/APIs:
- yaml
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.
{"case":{"caseId":"case:sha256:586ca971bf33eaff92bf25d77b18c541d0aa8f17c4ac92101ae5ceb9e93c3873","contract":["yaml.safe_load deserializes YAML strings and file-like streams (io.StringIO) into native Python dictionaries, lists, booleans, and numbers.","yaml.safe_dump serializes Python data structures to standard YAML with configurable formatting such as sort_keys and default_flow_style.","yaml.safe_load_all and yaml.safe_dump_all handle multi-document YAML streams delimited by document separators (---).","yaml.SafeLoader and yaml.SafeDumper support custom tag constructors and representers for domain-specific type serialization.","yaml.safe_load raises yaml.YAMLError on malformed syntax and yaml.constructor.ConstructorError on unsafe arbitrary python object tags."],"goal":"verify yaml in pkg:pypi/pyyaml@6.0.3","kind":"HOW","packages":["pkg:pypi/pyyaml@6.0.3"],"schemaVersion":1,"symbols":["yaml"]},"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/pyyaml@6.0.3"],"schemaVersion":1,"subject":"pkg:pypi/pyyaml@6.0.3","symbols":["yaml"],"verifierAdapter":"python@1"}
pyyaml==6.0.3
{
"schemaVersion": 1,
"goal": "verify yaml in pkg:pypi/pyyaml@6.0.3",
"kind": "HOW",
"packages": [
"pkg:pypi/pyyaml@6.0.3"
],
"symbols": [
"yaml"
]
}
import io
import yaml
from yaml.constructor import ConstructorError
from yaml.error import YAMLError
# 1. yaml.safe_load parses YAML strings and streams into native Python structures
yaml_content = """
app:
name: demo-service
port: 8080
debug: false
timeout: 30.5
null_val: null
features:
- auth
- metrics
summary: |
Multi-line
text block
"""
parsed_dict = yaml.safe_load(yaml_content)
assert isinstance(parsed_dict, dict), f"Expected dict, got {type(parsed_dict)}"
assert parsed_dict["app"]["name"] == "demo-service"
assert parsed_dict["app"]["port"] == 8080
assert parsed_dict["app"]["debug"] is False
assert parsed_dict["app"]["timeout"] == 30.5
assert parsed_dict["app"]["null_val"] is None
assert parsed_dict["app"]["features"] == ["auth", "metrics"]
assert parsed_dict["app"]["summary"].strip() == "Multi-line\ntext block"
# Safe load from io.StringIO stream
stream = io.StringIO("status: active\nretries: 3\n")
stream_data = yaml.safe_load(stream)
assert stream_data == {"status": "active", "retries": 3}
# 2. yaml.safe_dump serializes Python data structures to formatted YAML strings
data_to_dump = {
"name": "example",
"count": 10,
"enabled": True,
"items": ["one", "two"],
}
dumped_yaml = yaml.safe_dump(data_to_dump, sort_keys=True, default_flow_style=False)
assert "count: 10" in dumped_yaml
assert "enabled: true" in dumped_yaml
reloaded = yaml.safe_load(dumped_yaml)
assert reloaded == data_to_dump
# 3. yaml.safe_load_all and yaml.safe_dump_all handle multi-document streams
multi_doc_yaml = """---
doc: 1
type: header
---
doc: 2
type: payload
"""
docs = list(yaml.safe_load_all(multi_doc_yaml))
assert len(docs) == 2
assert docs[0] == {"doc": 1, "type": "header"}
assert docs[1] == {"doc": 2, "type": "payload"}
dumped_multi = yaml.safe_dump_all(docs, default_flow_style=False)
reloaded_multi = list(yaml.safe_load_all(dumped_multi))
assert reloaded_multi == docs
# 4. yaml.SafeLoader and yaml.SafeDumper support custom tag constructors and representers
class Coord:
def __init__(self, lat, lon):
self.lat = lat
self.lon = lon
def __eq__(self, other):
return isinstance(other, Coord) and self.lat == other.lat and self.lon == other.lon
class CustomLoader(yaml.SafeLoader):
pass
class CustomDumper(yaml.SafeDumper):
pass
def coord_constructor(loader, node):
fields = loader.construct_mapping(node)
return Coord(fields["lat"], fields["lon"])
def coord_representer(dumper, data):
return dumper.represent_mapping("!coord", {"lat": data.lat, "lon": data.lon})
CustomLoader.add_constructor("!coord", coord_constructor)
CustomDumper.add_representer(Coord, coord_representer)
point = Coord(37.5665, 126.9780)
custom_dump = yaml.dump({"location": point}, Dumper=CustomDumper)
assert "!coord" in custom_dump
loaded_point_data = yaml.load(custom_dump, Loader=CustomLoader)
assert isinstance(loaded_point_data["location"], Coord)
assert loaded_point_data["location"] == point
# 5. yaml.safe_load raises YAMLError on malformed syntax and ConstructorError on unsafe tags
try:
yaml.safe_load("invalid: [unclosed mapping: {")
raise AssertionError("Expected YAMLError on syntax error")
except YAMLError:
pass
try:
yaml.safe_load("!!python/object/apply:os.system ['echo dangerous']")
raise AssertionError("Expected ConstructorError on unsafe object tag")
except ConstructorError:
pass
print("CONTRACT PASS: yaml in pkg:pypi/pyyaml@6.0.3 verified offline")
Origin Seeder
anonymous