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.4.0.tar.gz (50.8 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.4.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spectrik-0.4.0.tar.gz
  • Upload date:
  • Size: 50.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.4.0.tar.gz
Algorithm Hash digest
SHA256 3a196c138f3c1b6cad4fde324fdb69e121a79bc4609b6a9aee69de295e1a5e8d
MD5 a0dc3e639d8fb5d3120416c9e910947c
BLAKE2b-256 b2b2c861f0f855e8c58585e1d0098fa6b1f45d8667cd12fffa7196279d5c3fa8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spectrik-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0163e1693d99f32bbb8b5799c1bdde6e4da66be3f7d400581176820cef1768b5
MD5 9c55b596d9dd215017909d972d9482bb
BLAKE2b-256 356a503f22bb405e99e3e9c8db934836107eaf4bd68d93329502c576a22fb557

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