Skip to main content

A specification and blueprint manager for declarative configuration-as-code tools.

Project description

spectrik

A generic specification and blueprint pattern for declarative configuration-as-code tools.

Overview

spectrik provides a reusable framework for building tools that apply declarative configurations to external systems. It includes:

  • Specification — an abstract base class for defining desired-state resources
  • SpecOp strategiesPresent, Ensure, and Absent wrappers that control when specs are applied or removed
  • Blueprint — a named, ordered collection of spec operations
  • Project — a top-level build target that orchestrates blueprints
  • HCL loading engine — parse .hcl files into blueprints and projects with decorator-based spec registration

Installation

pip install spectrik

Quick Start

import spectrik
from spectrik.hcl import load_blueprints, load_projects

# Register specs for HCL block decoding
@spectrik.spec("widget")
class Widget(spectrik.Specification["MyProject"]):
    def __init__(self, *, color: str):
        self.color = color

    def equals(self, ctx):
        ...

    def apply(self, ctx):
        ...

    def remove(self, ctx):
        ...

# Load from HCL files
blueprints = load_blueprints(Path("hcl"))
projects = load_projects(Path("hcl"), blueprints, project_type=MyProject)

# Build a project
projects["myapp"].build(dry_run=True)

HCL Support

spectrik uses HCL as its configuration language. Load .hcl files into a Workspace to define blueprints and projects:

import spectrik.hcl as hcl

ws = hcl.scan("./configs", project_type=MyProject, context={
    "env": os.environ,
    "name": "myapp",
    "cwd": os.getcwd,
})

ws["myapp"].build()

For manual control, parse individual files and feed them to a Workspace:

from spectrik import Workspace

ws = Workspace(project_type=MyProject)
ws.load(hcl.load(Path("blueprints.hcl"), context={...}))
ws.load(hcl.load(Path("projects.hcl"), context={...}))

Interpolation

String values in HCL files support ${...} variable interpolation. Pass a context dict when loading, and spectrik resolves references after parsing.

project "app" {
    description = "${name}"
    home        = "${env.HOME}/.config/${name}"
    workdir     = "${cwd}/data"
}

Dotted references walk the context using attribute or key access, so dicts, dataclasses, and Pydantic models all work naturally. If a context value is callable, it is invoked at resolution time — useful for values like "cwd": os.getcwd.

Escaping

Use $$ to produce a literal $ in the output. This is needed when HCL values contain template syntax meant for other tools:

You write in HCL Output after interpolation
${name} Resolved from context
$${name} Literal ${name}
$${{ secrets.TOKEN }} Literal ${{ secrets.TOKEN }}

For example, to embed a GitHub Actions workflow that mixes spectrik variables with Actions expressions:

blueprint "deploy" {
    present "file" {
        path    = ".github/workflows/deploy.yaml"
        content = <<-EOF
        name: Deploy
        on: [push]
        jobs:
          build:
            runs-on: ubuntu-latest
            steps:
              - uses: actions/checkout@v4
              - run: echo "Deploying ${app_name}"
                env:
                  TOKEN: $${{ secrets.GITHUB_TOKEN }}
        EOF
    }
}

In this example, ${app_name} is resolved by spectrik while $${{ secrets.GITHUB_TOKEN }} produces the literal ${{ secrets.GITHUB_TOKEN }} that GitHub Actions expects.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spectrik-0.3.1.tar.gz (44.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spectrik-0.3.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file spectrik-0.3.1.tar.gz.

File metadata

  • Download URL: spectrik-0.3.1.tar.gz
  • Upload date:
  • Size: 44.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spectrik-0.3.1.tar.gz
Algorithm Hash digest
SHA256 09460815dd8b0e78512d9550284fabc6901d044cd8e4d289f8f33d7bcf55ae0d
MD5 4b6f863996e3552c842eabf1d773731c
BLAKE2b-256 54707885290798adc2bcd47ea3099ed8c08090cb10142bac8ce288b1d1cda864

See more details on using hashes here.

File details

Details for the file spectrik-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: spectrik-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spectrik-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 432bb8d4e6a468d14ebd8f376fcb7a3cc5a2f40f7feba2a7a825b784fcc5d224
MD5 42104fdc2bba6e6e4d0d2b55f3a419e3
BLAKE2b-256 74626100aa247d80099e114be95588dabbb415fb951c05cbcd87e20082a0041b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page