Object-based, bidirectional string templating with declarative result types
Project description
regma
String templates with dataclass style
regma lets you define string templates through models behaving like standard dataclass.
It aims at solving a common scenario in the VFX/animation industry where we need to construct file paths from tokens and extract tokens from file paths.
regma lets you define the structure of your strings from typed fields and will handle for you:
- formatting of your model instances to string
- parsing of a string to model instances
Features
- Dataclass like structure: your models are properly typed and subclassable
- Typed fields:
string,integer,choice - Reference to other models: using annotations or using the
referencefield - Field validation: fields are validated both during formatting and parsing. Strictness can be configured in both directions independently
- Configurable delimiters:
{},<>,[]; global or per-model - Great developer experience: common linter and static type checker are supported. Most common IDEs (VS Code, PyCharm) provide autocompletion
Concrete example
from regma import TemplateModel
from regma import string, choice, integer
class Asset(TemplateModel):
type: str = choice(["chr", "prp", "set"])
code: str = string(r"[a-z][a-z0-9]+")
template = "{type}_{code}"
# Create an asset from its fields
asset = Asset("chr", "foo")
# Get it as a string
asset_str = asset.format() # or using str(asset)
# Parse an asset from its string
parsed_asset = Asset.parse("chr_foo")
# Build a more complex example to build a path
class GroomRetargetInfoPath(TemplateModel):
source_asset: Asset
target_asset: Asset
groom_name: str = string(r"[a-z][a-z0-9]+")
template = (
"/root/assets/{target_asset.type}/{target_asset}/{asset_target}_{groom}_{asset_target}.json"
)
# Create a new model
groom_info = GroomRetargetInfoPath(Asset("chr", "foo"), Asset("chr", "bar"), "hair")
# Get it as string
groom_info_path = groom_info.format() # /root/assets/chr/chr_foo/chr_foo_hair_chr_bar.json
# Parse the path to its information
parsed_groom_info = GroomRetargetInfoPath.parse("/root/assets/chr/chr_foo/chr_foo_hair_chr_bar.json")
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file regma-0.0.1.tar.gz.
File metadata
- Download URL: regma-0.0.1.tar.gz
- Upload date:
- Size: 81.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45d0f30789b51c72c1f69662f5b3fc1d0935c040685bfe5dfecc1f6a835b48ba
|
|
| MD5 |
7c9ad1b41f7af9ebf8648d6e4c982994
|
|
| BLAKE2b-256 |
1e785875a031ae7026ccf4cb5333983cc4a996af080109d8d280a70e48d5ccad
|
Provenance
The following attestation bundles were made for regma-0.0.1.tar.gz:
Publisher:
publish.yml on PoloB/regma
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
regma-0.0.1.tar.gz -
Subject digest:
45d0f30789b51c72c1f69662f5b3fc1d0935c040685bfe5dfecc1f6a835b48ba - Sigstore transparency entry: 1366795435
- Sigstore integration time:
-
Permalink:
PoloB/regma@b4dd672f68c8f22364cdf213349f3d6e2fdb4551 -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/PoloB
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b4dd672f68c8f22364cdf213349f3d6e2fdb4551 -
Trigger Event:
release
-
Statement type:
File details
Details for the file regma-0.0.1-py3-none-any.whl.
File metadata
- Download URL: regma-0.0.1-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a22e4abd07639aa8bbd03dfa9bfa1cd8bfa57d26f00419ae3bc13c97e2ee0fae
|
|
| MD5 |
30f90c83a529ac43dcd19e09588d5f4a
|
|
| BLAKE2b-256 |
768cb57efc56b371ec902c07968c503a145f86a09c854338d49477a06d2740e6
|
Provenance
The following attestation bundles were made for regma-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on PoloB/regma
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
regma-0.0.1-py3-none-any.whl -
Subject digest:
a22e4abd07639aa8bbd03dfa9bfa1cd8bfa57d26f00419ae3bc13c97e2ee0fae - Sigstore transparency entry: 1366795439
- Sigstore integration time:
-
Permalink:
PoloB/regma@b4dd672f68c8f22364cdf213349f3d6e2fdb4551 -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/PoloB
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b4dd672f68c8f22364cdf213349f3d6e2fdb4551 -
Trigger Event:
release
-
Statement type: