markdown
Class info¶
🛈 DocStrings¶
Schema to Markdown conversion utilities.
instance_to_markdown
¶
instance_to_markdown(
instance: BaseModel,
*,
template: str | None = None,
header_level: int = 1,
include_defaults: bool = True,
include_examples: bool = True,
include_constraints: bool = True,
include_values: bool = True,
display_mode: OutputMode = "table",
exclude_none: bool = False,
exclude_defaults_yaml: bool = False,
exclude_unset: bool = False,
indent: int = 2,
header_style: HeaderStyle = "default",
serialization_mode: SerializationMode = "json",
mask_value: str | None = None,
as_listitem: bool = True,
wrapped_in: str | None = None
) -> str
Convert a Pydantic model instance to Markdown documentation.
When include_values is True, the current values are shown alongside defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
BaseModel
|
The Pydantic model instance to document |
required |
template
|
str | None
|
Custom Jinja2 template string |
None
|
header_level
|
int
|
Starting header level (1 = h1, 2 = h2, etc.) |
1
|
include_defaults
|
bool
|
Include default values in the table |
True
|
include_examples
|
bool
|
Include examples section |
True
|
include_constraints
|
bool
|
Include constraints section |
True
|
include_values
|
bool
|
Include current instance values |
True
|
display_mode
|
OutputMode
|
Output format - "table", "python_code", or "yaml" |
'table'
|
exclude_none
|
bool
|
Exclude None values from YAML |
False
|
exclude_defaults_yaml
|
bool
|
Exclude default values from YAML |
False
|
exclude_unset
|
bool
|
Exclude unset values from YAML |
False
|
indent
|
int
|
YAML indentation |
2
|
header_style
|
HeaderStyle
|
Code block header style - "default" or "pymdownx" |
'default'
|
serialization_mode
|
SerializationMode
|
Pydantic serialization mode - "json" (default) or "python" |
'json'
|
mask_value
|
str | None
|
Placeholder string to use for masked values. Defaults to "!ENV ENV_VAR_NAME" |
None
|
as_listitem
|
bool
|
Wrap the YAML config in a list (default: True) |
True
|
wrapped_in
|
str | None
|
Wrap the config in a dict with this key (default: None) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Markdown string documenting the model instance |
Source code in src/schemez/markdown.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | |
model_to_markdown
¶
model_to_markdown(
model: type[BaseModel] | str,
*,
template: str | None = None,
header_level: int = 1,
include_defaults: bool = True,
include_examples: bool = True,
include_constraints: bool = True,
display_mode: OutputMode = "table",
mode: Literal["minimal", "maximal", "default"] = "default",
exclude_none: bool = False,
exclude_defaults: bool = False,
exclude_unset: bool = False,
indent: int = 2,
header_style: HeaderStyle = "default",
serialization_mode: SerializationMode = "json",
mask_value: str | None = None,
as_listitem: bool = True,
wrapped_in: str | None = None
) -> str
Convert a Pydantic model class to Markdown documentation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
type[BaseModel] | str
|
The Pydantic model class to document or import path string like 'module.path:ClassName' or 'module.path.ClassName' |
required |
template
|
str | None
|
Custom Jinja2 template string (uses DEFAULT_TEMPLATE if None) |
None
|
header_level
|
int
|
Starting header level (1 = h1, 2 = h2, etc.) |
1
|
include_defaults
|
bool
|
Include default values in the table |
True
|
include_examples
|
bool
|
Include examples section |
True
|
include_constraints
|
bool
|
Include constraints section |
True
|
display_mode
|
OutputMode
|
Output format - "table", "python_code", or "yaml" |
'table'
|
mode
|
Literal['minimal', 'maximal', 'default']
|
Generation mode for YAML examples |
'default'
|
exclude_none
|
bool
|
Exclude None values from YAML |
False
|
exclude_defaults
|
bool
|
Exclude default values from YAML |
False
|
exclude_unset
|
bool
|
Exclude unset values from YAML |
False
|
indent
|
int
|
YAML indentation |
2
|
header_style
|
HeaderStyle
|
Code block header style - "default" or "pymdownx" |
'default'
|
serialization_mode
|
SerializationMode
|
Pydantic serialization mode - "json" (default) or "python" |
'json'
|
mask_value
|
str | None
|
Mask value for SecretStr objects |
None
|
as_listitem
|
bool
|
Wrap the YAML config in a list (default: True) |
True
|
wrapped_in
|
str | None
|
Wrap the config in a dict with this key (default: None) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Markdown string documenting the model |
Source code in src/schemez/markdown.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | |
model_union_to_markdown
¶
model_union_to_markdown(
union_type: Any,
*,
template: str | None = None,
header_level: int = 1,
include_defaults: bool = True,
include_examples: bool = True,
include_constraints: bool = True,
display_mode: OutputMode = "table",
mode: Literal["minimal", "maximal", "default"] = "default",
exclude_none: bool = False,
exclude_defaults: bool = False,
exclude_unset: bool = False,
indent: int = 2,
header_style: HeaderStyle = "default",
serialization_mode: SerializationMode = "json",
mask_value: str | None = None,
as_listitem: bool = True,
wrapped_in: str | None = None
) -> str
Convert a Union type containing Pydantic models to Markdown documentation.
Runtime-inspects the Union and generates markdown for all included BaseModel types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
union_type
|
Any
|
A Union type containing Pydantic model classes or import path string like 'module.path:UnionAlias' or 'module.path.UnionAlias' |
required |
template
|
str | None
|
Custom Jinja2 template string (uses DEFAULT_TEMPLATE if None) |
None
|
header_level
|
int
|
Starting header level (1 = h1, 2 = h2, etc.) |
1
|
include_defaults
|
bool
|
Include default values in the table |
True
|
include_examples
|
bool
|
Include examples section |
True
|
include_constraints
|
bool
|
Include constraints section |
True
|
display_mode
|
OutputMode
|
Output format - "table", "python_code", or "yaml" |
'table'
|
mode
|
Literal['minimal', 'maximal', 'default']
|
Generation mode for YAML examples |
'default'
|
exclude_none
|
bool
|
Exclude None values from YAML |
False
|
exclude_defaults
|
bool
|
Exclude default values from YAML |
False
|
exclude_unset
|
bool
|
Exclude unset values from YAML |
False
|
indent
|
int
|
YAML indentation |
2
|
header_style
|
HeaderStyle
|
Code block header style - "default" or "pymdownx" |
'default'
|
serialization_mode
|
SerializationMode
|
Pydantic serialization mode - "json" (default) or "python" |
'json'
|
mask_value
|
str | None
|
Placeholder string to use for masked values. Defaults to "!ENV ENV_VAR_NAME" |
None
|
as_listitem
|
bool
|
Wrap the YAML config in a list (default: True) |
True
|
wrapped_in
|
str | None
|
Wrap the config in a dict with this key (default: None) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Markdown string documenting all models in the union |
Source code in src/schemez/markdown.py
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 | |
schema_to_markdown_context
¶
schema_to_markdown_context(
model: type[BaseModel],
*,
header_level: int = 1,
include_defaults: bool = True,
include_examples: bool = True,
include_constraints: bool = True
) -> dict[str, Any]
Convert a Pydantic model to a Jinja2 template context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
type[BaseModel]
|
The Pydantic model class to convert |
required |
header_level
|
int
|
Starting header level (1 = h1) |
1
|
include_defaults
|
bool
|
Include default values in output |
True
|
include_examples
|
bool
|
Include examples in output |
True
|
include_constraints
|
bool
|
Include constraints section |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary suitable for rendering with the markdown template |
Source code in src/schemez/markdown.py
setup_jinjarope_filters
¶
Set up schemez markdown filters for jinjarope.
This function is used as an entry point for the jinjarope.environment extension group to add markdown-related filters to Jinja2 environments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
Any
|
The Jinja2 environment to modify |
required |