Output Writers¶
apcore-toolkit provides several ways to export the ScannedModule metadata into formats used by the apcore ecosystem.
YAMLWriter¶
Generates individual .binding.yaml files for each scanned module. These files are typically placed in an extensions/ or bindings/ directory and loaded by apcore.BindingLoader.
Features¶
- File-per-Module: Each module is written to its own file for easy management.
- Sanitized Filenames: Replaces periods and special characters in module IDs to ensure valid file names.
- Header Injection: Optionally adds a "Generated by" header to all files.
from apcore_toolkit import YAMLWriter
writer = YAMLWriter()
writer.write(modules, output_dir="./bindings")
import { YAMLWriter } from "apcore-toolkit";
const writer = new YAMLWriter();
writer.write(modules, { outputDir: "./bindings" });
PythonWriter / TypeScriptWriter¶
Generates source files containing decorator-based wrapper functions. This is useful for migrating legacy code to the apcore decorator pattern without manual re-writing.
Features¶
- Auto-Decorators: Generates the decorator with all extracted metadata.
- Target Integration: Points to the original view function as the
targetof the module. - Standard Formatting: Produces clean, idiomatic code for the target language.
from apcore_toolkit import PythonWriter
writer = PythonWriter()
writer.write(modules, output_dir="./generated_apcore")
import { TypeScriptWriter } from "apcore-toolkit";
const writer = new TypeScriptWriter();
writer.write(modules, { outputDir: "./generated_apcore" });
RegistryWriter¶
Directly registers the scanned modules into an active apcore.Registry instance. This is ideal for "live" scanning where you want to expose existing endpoints without generating intermediate files.
Features¶
- No Disk Usage: Modules are held only in memory.
- Hot-Reload Ready: Can be re-run to refresh the Registry as endpoints change.
from apcore import Registry
from apcore_toolkit import RegistryWriter
registry = Registry()
writer = RegistryWriter()
writer.write(modules, registry)
import { Registry } from "@anthropic/apcore";
import { RegistryWriter } from "apcore-toolkit";
const registry = new Registry();
const writer = new RegistryWriter();
writer.write(modules, registry);
Choosing a Writer¶
| Use Case | Recommended Writer |
|---|---|
| Configuration-first approach | YAMLWriter |
| Migrating legacy views to decorators | PythonWriter |
| Live, dynamic module exposure | RegistryWriter |
| Fast, zero-config integration | RegistryWriter |