-
Notifications
You must be signed in to change notification settings - Fork 0
API Reference
小树 edited this page May 2, 2026
·
2 revisions
load(
path: str | Path,
*,
version: str | None = None,
format: FormatName | None = None,
encoding: str = "utf-8",
) -> DocumentLoad and parse an APICORE configuration file from disk.
| Parameter | Type | Default | Description |
|---|---|---|---|
path |
str | Path |
required | Path to the configuration file |
version |
str | None |
None |
Force APICORE version ("v1" or "v2") |
format |
FormatName | None |
None |
Override format ("json", "yaml", "toml") |
encoding |
str |
"utf-8" |
File encoding |
Returns a Document (V1Document or V2Document).
from apicore import load
doc = load("config.api.yaml")
doc = load("config.api.json", version="v1")loads(
data: str | bytes,
*,
version: str | None = None,
format: FormatName | None = None,
encoding: str = "utf-8",
) -> DocumentParse an APICORE configuration from a string or bytes.
| Parameter | Type | Default | Description |
|---|---|---|---|
data |
str | bytes |
required | Raw configuration content |
version |
str | None |
None |
Force APICORE version ("v1" or "v2") |
format |
FormatName | None |
None |
Input format ("json", "yaml", "toml") |
encoding |
str |
"utf-8" |
Encoding for str input |
Returns a Document (V1Document or V2Document).
from apicore import loads
doc = loads('{"friendly_name": "Demo", ...}', format="json")validate(
path: str | Path,
*,
version: str | None = None,
format: FormatName | None = None,
encoding: str = "utf-8",
) -> DocumentValidate an APICORE configuration file. Raises an exception on invalid input. Alias for load().
This function returns the parsed Document; it does not return True or False.
from apicore import validate
doc = validate("config.api.toml", format="toml")
print(doc.apicore_version)- If
APICORE_versionis present in the document, that version is used. - If
versionis explicitly passed, it overrides detection (and conflicts withAPICORE_versionraise an error). - If neither is present, defaults to v2.
| Value | Resolved |
|---|---|
"1", "1.0", "v1"
|
v1 |
"2", "2.0", "v2"
|
v2 |
| Extension | Format |
|---|---|
.json |
json |
.yaml, .yml
|
yaml |
.toml |
toml |
If the file suffix is unsupported and format is not provided, parsing raises ValidationError.
-
ParseErroris raised for invalid JSON, YAML, or TOML syntax. -
ValidationErroris raised when the decoded document violates APICORE rules. -
APICoreErroris the shared base class if you want one catch-all branch.
© 2026 Little Tree Studio & SRInternet Studio.
Licensed under CC BY-SA 4.0.