Skip to main content

Sigils

“An inscribed or painted symbol considered to have magical power.”

Sigils is a Python library for text and meta-text interpolation. It provides advanced capabilities such as context-based interpolation, function execution, nested and recursive interpolation, case-insensitive matching, and global context support.

Any Python object can be provided as context, including nested dictionaries, lists, and functions. Sigils can be used directly from Python or from the command line. Sigils is thread-safe and has no dependencies outside of the Python standard library.

Installation

Install Sigils using pip:

pip install sigils

Usage

Here’s a simple example of using Sigils:

from sigils import Sigil

context = {"user": {"name": "Alice"}}
s = Sigil("Hello, %[user.name]!")
print(s % context)  # Outputs: Hello, Alice!

Sigils can handle function execution and nested interpolation:

from sigils import Sigil

context = {
    "user": {
        "name": "Alice",
        "greet": lambda name: f"Hello, {name}!"
    }
}

s = Sigil("%[user.greet:user.name]")
print(s % context)  # Outputs: Hello, Alice!

s = Sigil("%[user.greet:%%user.name]")
print(s % context)  # Outputs: Hello, %user.name! %user.name is treated as a literal value

Sigils support case-insensitive matching and global context fallback:

from sigils import Sigil, Sigil.Context

global_context = {"greeting": "Hello, world!"}
with Sigil.Context(global_context):
    s = Sigil("%[GREETING]")
    print(s % {})  # Outputs: Hello, world!

Command-Line Usage

Sigils can be used directly from the command line. Here’s an example:

sigils "Hello, %[user.name]!" -c context.json

In this example, “context.json” is a JSON file with a structure like {“user”: {“name”: “Alice”}}. The command will output: “Hello, Alice!”.

Considerations

  • Function Execution: If the value of a Sigil is a callable function, it will be executed and its return value used in the string. Ensure all function values in your context are safe to execute.

  • Recursion Depth: Sigils handles up to 6 levels of nested interpolation by default. Adjust this limit by passing a different max_depth value to the interpolate method.

  • Thread Safety: The global context in Sigils is thread-safe. However, if you’re using mutable objects in your context and modifying them from multiple threads, manage thread safety at the application level.

  • Case-Insensitive Matching: If a key fails to resolve, a case-insensitive lookup is attempted. This only works if the keys in your context are all unique when lowercased.

Performance

Sigils is designed with performance in mind. In typical use cases, Sigils performs competitively with Python’s built-in string formatting.

License

Sigils is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for sigils 0.3.5

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

Source distribution (sdist)

Source distribution for sigils 0.3.5
File Size Uploaded Provenance Actions
sigils-0.3.5.tar.gz 16.3 kB Without provenance Details for sigils-0.3.5.tar.gz

Built distribution (wheel)

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

Total release size: 30.9 kB

Release files / sigils-0.3.5.tar.gz

Download URL sigils-0.3.5.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1ecb99483149fd81bed8e7c218bac52bc8aa76333d3a478905e654a5ef2fb90b
BLAKE2b-256 checksum
How to use checksums
40ee37724903c14d75eff4ea8c8290070abf4a896be06c23190a884efbcfed2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Release files / sigils-0.3.5-py3-none-any.whl

Download URL sigils-0.3.5-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
762655b64e15e1563bd69d111a95b484ce7cfb632142ffef9a0176cc25ff7c48
BLAKE2b-256 checksum
How to use checksums
fcbd1534b19f85672244eaaaf77fd05fc5046835421c36d1354febd4fb278ef6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Security for sigils 0.3.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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