Skip to main content

Dataclass runtime machinery for declarative DSLs

Project description

dataclass-dsl

Build declarative Python DSLs where infrastructure and configuration look like this:

from . import *

class LogBucketEncryption:
    resource: s3.Bucket.BucketEncryption
    server_side_encryption_configuration = [LogBucketEncryptionRule]

class LogBucket:
    resource: s3.Bucket
    bucket_encryption = LogBucketEncryption
    public_access_block_configuration = LogBucketPublicAccessBlock
    versioning_configuration = LogBucketVersioning

No decorators. No function calls. No boilerplate.

The Pattern

Domain packages built on dataclass-dsl share three properties:

Property What it means
Single import from . import * — everything available, loaded in dependency order
Zero decorators Classes are plain declarations, machinery is invisible
Flat wrappers Each class wraps a resource type with simple attribute assignments

The result reads like configuration, but with full Python power: IDE autocomplete, type checking, refactoring, and the ability to use variables, loops, and conditionals when needed.

What This Enables

Reference other resources by class name:

class AppSubnet:
    resource: Subnet
    vpc = AppVPC                    # Reference to another resource
    cidr_block = "10.0.1.0/24"

Reference specific attributes:

class LambdaFunction:
    resource: Function
    role_arn = ExecutionRole.Arn    # Gets the Arn of ExecutionRole

Compose nested configurations:

class BucketEncryption:
    resource: s3.Bucket.BucketEncryption
    server_side_encryption_configuration = [EncryptionRule]

class MyBucket:
    resource: s3.Bucket
    bucket_encryption = BucketEncryption

Use lists and maps of references:

class LoadBalancer:
    resource: ALB
    subnets = [SubnetA, SubnetB, SubnetC]
    security_groups = [WebSecurityGroup]

How It Works

dataclass-dsl provides the runtime machinery that makes this pattern possible:

  • Automatic dependency detection — References between classes are detected at runtime
  • Topological ordering — Resources are serialized in dependency order
  • Multi-file supportsetup_resources() loads files in the right order, enabling from . import *
  • IDE stub generation — Full autocomplete and type checking despite dynamic imports

Domain packages use these primitives to create decorators and loaders that are invisible to end users.

Installation

pip install dataclass-dsl

Using a Domain Package

If you're using a domain package built on dataclass-dsl (like an AWS CDK alternative or Kubernetes manifest generator), follow that package's documentation. You'll write clean declarative classes without needing to understand the internals.

Building a Domain Package

If you're creating a domain package, see the Internals Guide for:

  • Creating a domain-specific decorator with create_decorator()
  • Setting up multi-file packages with setup_resources()
  • Implementing a Provider for your target format
  • Generating IDE stubs for from . import *

Also see the AWS S3 example to see what a domain package produces.

Documentation

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

dataclass_dsl-1.0.0.tar.gz (58.3 kB view details)

Uploaded Source

Built Distribution

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

dataclass_dsl-1.0.0-py3-none-any.whl (53.6 kB view details)

Uploaded Python 3

File details

Details for the file dataclass_dsl-1.0.0.tar.gz.

File metadata

  • Download URL: dataclass_dsl-1.0.0.tar.gz
  • Upload date:
  • Size: 58.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dataclass_dsl-1.0.0.tar.gz
Algorithm Hash digest
SHA256 325ccad78d7bccce369bd68a4782b4f20ae69077db0f6ca966f3a4f38329e0e8
MD5 93e6f9aef9109ca3a72c1bbe20d90a94
BLAKE2b-256 c1ab92f39b5f0c7f24208681d5e89017f2949b6993ace277f8e102958a48c12c

See more details on using hashes here.

Provenance

The following attestation bundles were made for dataclass_dsl-1.0.0.tar.gz:

Publisher: release.yml on lex00/dataclass-dsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dataclass_dsl-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dataclass_dsl-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 53.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dataclass_dsl-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05b6cef4763f9ac5081ebad16e65f2bd53c68cdf3b1eeccf17d7afe5456f2ddf
MD5 9a01d26640b7fcde88acfac9c7ef54ac
BLAKE2b-256 67180ecaa381347dbd8c7ce0896e7c8a1333376b2100697a719c6d2791be10da

See more details on using hashes here.

Provenance

The following attestation bundles were made for dataclass_dsl-1.0.0-py3-none-any.whl:

Publisher: release.yml on lex00/dataclass-dsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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