Skip to main content

Shikumi

Shikumi is a library for building structured document generators, custom DSLs, architecture validators, and similar systems on top of Python.

Shikumi itself does not provide those features as individual built-ins.

Instead, you define a specification that determines what elements exist, what attributes and relationships they have, what structure they belong to, what counts as a valid state, and what can be produced from the resulting semantic view.

For example, transforming the resulting semantic view into Markdown becomes document generation. Defining custom information types and description mechanisms such as service, entity, and uses creates a DSL. A rule such as "only dependencies from the application layer to the domain layer are allowed" becomes architecture validation.

In other words, Shikumi does not deal with architecture, DSLs, or documents themselves. It is a common foundation for building systems with custom meaning and rules on top of Python, interpreting them, and using the result.

Main uses

Shikumi can be used, for example, to:

  • generate documents, configuration, reports, and other artifacts from semantic views constructed from descriptions in Python code;
  • create documents with explicit meaning and structure for rapid communication with LLMs;
  • describe domain-specific attributes, classifications, and relationships on Python classes and modules;
  • build a Python-based DSL with custom descriptors and information types;
  • define the package, module, and class structure a project is expected to have;
  • apply the same specification to multiple Python packages; and
  • express software architecture structure and dependency directions, then build validation around them.

These uses are not built into Shikumi itself. They are created by defining a specification for the intended purpose.

Installation

pip install shikumi

Current version: 0.1.0.

Shikumi targets Python 3.11 and later.

Quick start

The following example defines an information type named title and describes it through two kinds of descriptors: @= and a decorator.

from shikumi import (
    DescriptorUseRule,
    Diagnostic,
    InformationType,
    Shikumi,
    StructuralKind,
    StructureSelector,
    validator,
)
from shikumi.standard import assignment, decorator, information_type_rule

Title = InformationType("title", str)

title = assignment(Title)
titled = decorator(Title)


class Overview:
    title @= "Overview"


@titled("Tutorial")
class Tutorial:
    pass


@validator(focus=StructuralKind.ENTITY)
def require_title(view):
    if not view.focused.has(Title):
        yield Diagnostic("title is required")


docs = Shikumi(
    information_types=[Title],
    validators=[require_title, information_type_rule(Title)],
    descriptor_rules=[
        DescriptorUseRule(
            descriptor=title,
            allowed=StructureSelector(kind=StructuralKind.ENTITY),
            name="title",
        )
    ],
)

assert docs.view(Overview).focused.values(Title) == ("Overview",)
assert docs.validate(Overview).is_valid

InformationType defines what something means; descriptors define how that meaning is written in Python. Shikumi combines the information types, validation rules, descriptor-use rules, and other parts it recognizes, constructs a semantic view with view(), and validates it with validate().

title @= "Overview" is not ordinary attribute assignment. The descriptor created by assignment(Title) attaches information to Overview after the class has been created. @= is a Standard notation for describing meaning defined by the specification while keeping a natural class-body form.

Warning

Only pass trusted Python modules and packages to Shikumi.

Shikumi interprets objects that exist after Python execution. When a module or package is supplied by import path, it is imported and executed as ordinary Python before Shikumi constructs its semantic view. This is true whether that semantic view is used for validation, realization, or another operation. Target code can perform arbitrary actions with the same permissions as a normal import in the current Python process.

Be especially careful with validation: it is not a sandboxed or static safety check. Do not pass untrusted Python code to Shikumi in order to determine whether it is safe.

Runtime determination principle

Shikumi does not re-read Python source as an AST. Modules and packages used as description bodies are imported as ordinary Python, and Shikumi observes the runtime objects, information, and descriptor uses that exist after execution.

Python source
    ↓ execute / import
runtime objects + information + descriptor uses
    ↓
Shikumi
    ↓ interpretation
semantic view
   /          \
validation     realization
                  ↓
               artifact

Therefore, when a target module is loaded for validation, its top-level code is executed just as it is during a normal import. Shikumi is not a static analyzer that determines safety without executing the target.

What Shikumi does not inspect automatically

Shikumi does not automatically analyze Python ASTs or source syntax, actual import or call graphs, or modules that have not been imported. The standard PythonStructure also does not treat functions or methods as entities. Model any additional information or targets explicitly in your norms or in a custom Structure.

Validation and realization

Shikumi reads Python objects and the information attached to them according to a structure and constructs a semantic view.

Validation applies validation rules to that semantic view. You can define conditions for a specific purpose, such as whether a package contains required modules, whether a class has required information, or whether relationships between elements satisfy a rule.

A semantic view is not limited to validation. By applying an independent Realizer, it can be realized into arbitrary artifacts such as Markdown, configuration, or reports. Multiple Realizers can be applied to the same semantic view.

Standard

shikumi.standard provides reusable concrete functionality built from Core mechanisms.

Its main facilities include assignment for @=, decorator for decorator-based description, docstring for turning docstrings into information, and PackageTreeStructure for interpreting a package tree through ordinary imports.

Purpose-specific meanings such as service, entity, layer, and term are not part of Standard. They are defined by the user's specification.

CLI

The CLI can wire together a Shikumi exposed by a specification body, a description body, and an independent Realizer using ordinary Python imports.

The CLI entry point is shikumi. The same CLI is also available through python -m shikumi.

Validation:

shikumi validate \
  --shikumi myproject.shikumi_lib.norms:app \
  --body myproject.application \
  --structure-spec myproject.shikumi_lib.norms:app_structure \
  --format text

Realization:

shikumi realize \
  --shikumi myproject.shikumi_lib.norms:app \
  --body myproject.application \
  --realizer myproject.shikumi_lib.realizers.markdown:markdown \
  --output API.md \
  --format json

realize does not implicitly perform validation or a realizability check. These are treated as independent operations.

Examples

examples/ contains four official examples that approach Shikumi from different directions. They are bundled in the distribution as reference source, but they are not a public import package or CLI entry point.

  • architecture — define application-specific dependency rules and validate architecture
  • structured_docs — construct a semantic view from Python descriptions and realize it as Markdown
  • web_api — an end-to-end example combining a custom DSL, validation, and realization
  • structure_from_body — derive a structural regulation from one description body and validate another body for structural conformance

For precise concept definitions, use the glossary as the reference.

About the public documentation

All public documentation is provided in English. Canonical sources live under _internal/document_source/; shikumi-devdoc realizes committed Japanese intermediates under _internal/document_build/ja/, and those intermediates are used as the translation source for the public documents.

Intermediate files are generated artifacts and are not edited directly. If a public document, an intermediate document, and a canonical source differ, the canonical document source takes precedence.

License

MIT License. See LICENSE.

Metadata

Release files for shikumi 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shikumi 0.1.0
File Size Uploaded
shikumi-0.1.0.tar.gz 47.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shikumi 0.1.0
File Interpreter ABI Platform
shikumi-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 120.2 kB

Release files / shikumi-0.1.0.tar.gz

Download URL shikumi-0.1.0.tar.gz
Size 47.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3a2ec15da745d964bb8be55b8eaadee27f2cc6a025d9e8aab8d40a9e69083be5
BLAKE2b-256 checksum
How to use checksums
4a3ae6cb451c7b5eab20214f868074cc57b1b7b419b2c3d1141f610032de5bbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / shikumi-0.1.0-py3-none-any.whl

Download URL shikumi-0.1.0-py3-none-any.whl
Size 72.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7aa9eb80506e40281cdb4725bdc821e76af01248bbb28c0c629b95bd664dc006
BLAKE2b-256 checksum
How to use checksums
800f76f2ed3efe07a596ff83c0aa9fbdb143c3da2375e18e62b7351476664261
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release history Release notifications | RSS feed

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page