Skip to main content

Neutralts template engine for the Web, python package

Project description

Python package for Neutral TS

Neutral is a templating engine for the web written in Rust, designed to work with any programming language (language-agnostic) via IPC/Package and natively as library/crate in Rust.

Install Package

pip install neutraltemplate

Usage

See: examples

Basic usage with file

from neutraltemplate import NeutralTemplate

schema = """
{
    "config": {
        "cache_prefix": "neutral-cache",
        "cache_dir": "",
        "cache_on_post": false,
        "cache_on_get": true,
        "cache_on_cookies": true,
        "cache_disable": false,
        "disable_js": false,
        "filter_all": false
    },
    "inherit": {
        "locale": {
            "current": "en",
            "trans": {
                "en": {
                    "Hello nts": "Hello",
                    "ref:greeting-nts": "Hello"
                },
                "es": {
                    "Hello nts": "Hola",
                    "ref:greeting-nts": "Hola"
                }
            }
        }
    },
    "data": {
        "hello": "Hello World"
    }
}
"""

template = NeutralTemplate("file.ntpl", schema_str=schema)
contents = template.render()

# e.g.: 200
status_code = template.get_status_code()

# e.g.: OK
status_text = template.get_status_text()

# empty if no error
status_param = template.get_status_param()

# Check for errors
if template.has_error():
    # Handle error
    pass

Using Python dictionaries (schema_obj)

You can pass Python dictionaries directly without JSON serialization:

from neutraltemplate import NeutralTemplate

schema_dict = {
    "data": {
        "title": "Hello World",
        "items": ["one", "two", "three"]
    }
}

# Pass dict directly via schema_obj parameter
template = NeutralTemplate("file.ntpl", schema_obj=schema_dict)
contents = template.render()

Using set_source() for inline templates

from neutraltemplate import NeutralTemplate

template = NeutralTemplate()
template.set_source("{:;data.title:}")
template.merge_schema_obj({"data": {"title": "Hello"}})
contents = template.render()  # "Hello"

Multiple renders with the same NeutralTemplate instance

You can render the same NeutralTemplate instance multiple times:

from neutraltemplate import NeutralTemplate

template = NeutralTemplate("file.ntpl", schema_obj={"data": {"title": "Hello"}})

# First render
contents1 = template.render()

# You can modify the schema and render again
template.merge_schema_obj({"data": {"title": "World"}})
contents2 = template.render()

MessagePack schema

You can pass MessagePack bytes in the constructor or merge them later.

from neutraltemplate import NeutralTemplate

# {"data": {"key": "value"}}
schema_msgpack = bytes([
    129, 164, 100, 97, 116, 97, 129, 163, 107, 101, 121, 165, 118, 97, 108, 117, 101
])

template = NeutralTemplate("file.ntpl", schema_msgpack=schema_msgpack)
template.merge_schema_msgpack(schema_msgpack)

Performance Notes

For best performance, choose the schema input method based on your use case. Current project benchmarks are in local_bench/ and should be treated as workload-dependent:

Method Performance Notes
schema_obj Best in current local bench Python dict/list converted recursively to JSON internally
schema_msgpack Near best in current local bench Binary format, validated at API boundary
schema_str (JSON) Usually slower for larger schemas Requires JSON parsing

Recommendation: Use schema_obj for simplicity. For large schemas and hot paths, benchmark your own workload (local_bench/bench.py) before deciding.

# Recommended: schema_obj (fastest and simplest)
template = NeutralTemplate("file.ntpl", schema_obj={"data": {"title": "Hello"}})

# Good alternative: schema_msgpack (nearly as fast)
template = NeutralTemplate("file.ntpl", schema_msgpack=msgpack_bytes)

# Often slower for large schemas: schema_str (JSON parsing cost)
template = NeutralTemplate("file.ntpl", schema_str='{"data": {"title": "Hello"}}')

API Reference

Constructor

NeutralTemplate(
    path=None,           # Path to template file
    schema_str=None,     # JSON schema as string
    schema_msgpack=None, # MessagePack schema as bytes
    schema_obj=None      # Python dict/list as schema
)

Only one of schema_str, schema_msgpack, or schema_obj can be used at a time. schema_str and schema_msgpack are validated by neutralts during render().

Methods

Method Description
render() Render template (optimized internally with render_once)
set_path(path) Set template file path
set_source(source) Set template source code directly
merge_schema(schema_str) Merge JSON schema from string
merge_schema_msgpack(bytes) Merge MessagePack schema
merge_schema_obj(obj) Merge Python dict/list as schema
get_status_code() Get HTTP status code (e.g., "200")
get_status_text() Get HTTP status text (e.g., "OK")
get_status_param() Get additional error parameter
has_error() Returns True if error occurred during render

Links

Neutral TS template engine Python Package.

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

neutraltemplate-1.4.0.tar.gz (24.8 kB view details)

Uploaded Source

Built Distributions

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

neutraltemplate-1.4.0-cp313-cp313-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.13Windows x86-64

neutraltemplate-1.4.0-cp313-cp313-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

neutraltemplate-1.4.0-cp313-cp313-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

neutraltemplate-1.4.0-cp313-cp313-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

neutraltemplate-1.4.0-cp313-cp313-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

neutraltemplate-1.4.0-cp312-cp312-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.12Windows x86-64

neutraltemplate-1.4.0-cp312-cp312-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

neutraltemplate-1.4.0-cp312-cp312-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

neutraltemplate-1.4.0-cp312-cp312-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

neutraltemplate-1.4.0-cp312-cp312-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

neutraltemplate-1.4.0-cp311-cp311-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.11Windows x86-64

neutraltemplate-1.4.0-cp311-cp311-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

neutraltemplate-1.4.0-cp311-cp311-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

neutraltemplate-1.4.0-cp311-cp311-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

neutraltemplate-1.4.0-cp311-cp311-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

neutraltemplate-1.4.0-cp310-cp310-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.10Windows x86-64

neutraltemplate-1.4.0-cp310-cp310-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

neutraltemplate-1.4.0-cp310-cp310-manylinux_2_28_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

neutraltemplate-1.4.0-cp310-cp310-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

neutraltemplate-1.4.0-cp310-cp310-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

Details for the file neutraltemplate-1.4.0.tar.gz.

File metadata

  • Download URL: neutraltemplate-1.4.0.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.4

File hashes

Hashes for neutraltemplate-1.4.0.tar.gz
Algorithm Hash digest
SHA256 f4dc69a221b56f3eb2d2ec304bae48c64b666c0db3ad4ce0fbbcfe4b96f392a9
MD5 50007ec23172b15cf784780339cb8c43
BLAKE2b-256 331a8c6e28b0a6578f379fa8a910524ff4054665bb629002f29bc78717a4c48a

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 fd3f5b1bff7bfcc806312d5d665caf4a65259eee579e3eabc4c288c78591c16e
MD5 660ca1668badf80780a0cd62c36af365
BLAKE2b-256 96b56cab2e4fc23eb3596163ca8aac41d60fad84b366688cae176f300dc7a8ab

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0d97b72e7e6ce7706188306ae7bea4b51854a4e7446691a2740371390c2f759f
MD5 5f36350532312c42c07a0c6eab0d6369
BLAKE2b-256 68ebeffd807ca628257295ad66dddc7b3e3843a30388eba5da223d02da663e0e

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cd06a44c72a117ecd6be9afd23edd8f3b992bfdcda6dd8c555072584fc9b6776
MD5 5bfda6d39bc1ef56c3530030c0937db5
BLAKE2b-256 1d79ef5815cb77efae354c183a61f69218eeb5ed0f7287b5fc92adde9eade265

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 00ed2f08619d65483ce8406b60c910dcb7efdcede00c0bdc1a1e4b949f83b204
MD5 8dc365f4fc752dbd3b7806fd37dd7093
BLAKE2b-256 399faacb45b4c9f22269bf717e8223917577ed8fcc62e800c22da902e6cb36f9

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0f2444eb5f3621d9e872dc4f9a8a86291701c44898b8ba10da5f2c9cab9e8dd3
MD5 32d32d710da716488c0c747343523ea4
BLAKE2b-256 efba1396b51b2765fa3f26cfdfac7e3a6be43e06be74d724a8d55b9ff829c4e7

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 72145b073a589e867d41ce1a8c03aa90125a3b5ee6efeaab7bfee7b253082c2e
MD5 22bc599499490273d389f566b05e1302
BLAKE2b-256 4705386ac25e263ac50ba9d9c97c6ad6692ab6703f3d9a65f8fdf1fb5006f34c

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2af95f9d0174c37a45f914f041ec1b9414b4c9ae8fe0336fa61327741f099820
MD5 ecb0a1e95cc1b0d2cb30b6eb1553f398
BLAKE2b-256 4070d595da4f88dafe31fc512f4336e85d5b189bf3939fca5e769b584b22b676

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c19c6d4ff965d1ac572f2b91ac0cd687772c209d5d1292facd4716da62b917a2
MD5 001c65afb243dae7e7ae06d9644d5a1b
BLAKE2b-256 ccb7013dd5869c672b3bd14333064bbc2e24ebbf3d864f5ef076725ca7b98818

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 385b1a13691b2238580d15f3425b89c553604360c3ae1f30aca1c301b602076a
MD5 e957a8034669b0f3d52f0625443595df
BLAKE2b-256 fe248a0ace4ace55edc20da6628d4427c296684fcef996ff31e97e233055dce9

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 798757e7e03ed12828afdf95b79513ec4e034d8b56d37664689db6e55973bb92
MD5 d3a202fcfe4e9f45a504584a850b7f85
BLAKE2b-256 1fcfbe5b9996bd3f5c09c256fc57875496c9df3794ee51ff8107e51a93961a64

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a0c23ff3d5f04311a56d41005e292f584dee301709d13fb875911f298ead2c83
MD5 c587520621d9caa17937caa965e7b8ac
BLAKE2b-256 40254e66da1ec6e8607781406312d384e3449261b4eab7871ff42a5018d1f3f6

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 86e58f951cf3e3844f6afe7a8c710d49b0082c257dec0066da2c8f0aa6777ec3
MD5 16fe9cb888677a01ad56fd5a19dbe2b3
BLAKE2b-256 625ae28d8c1bcb348b17f94a91e701e842425318d9864afb1486811681e67913

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 15a6be8c118cfa31dada509e6b5c8853c7bd51b6c221b9d4fb5aac102bdea32b
MD5 c7c9d0184391ee775ee5eb3525f00b0e
BLAKE2b-256 2b4e2ab66082c2bb97a03b097f768ff5880f689edd422f347f91b49dbf2bcc5a

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fb3e78c0e1d8460052b829c521e627a53efc37417915faa6607bdc44856e0805
MD5 61d4026405badf0b8e2c9f6d991b39b9
BLAKE2b-256 548d6ecbd74ef60a871f85de8d53f9eec5682eeb9b866d5a931edbfca159ab05

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 13152205a29882cb5fe058fa731cf8468c37cee65fe0c0ff19168b98db33ae75
MD5 e7f0741749734dfb43bcac57f4ac4900
BLAKE2b-256 454158cf6e64c3ee9fd68b42c19f552a73b2a81016e22dc8d43656670b1bbea6

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ffe39bee792df68d97a2b58afd492208e15158c1b68d8f52e93fa04d0a17f996
MD5 1dd0d36b1e0905a426c98d27d7cbdecf
BLAKE2b-256 c635f2c3c5b26c41f2e7e7edd09cd46afc513238168ec19bd5cb3e0197b11d60

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b1a7b9f25fc254e558e6e3733c53ba9554d6235534d591becede266173902e02
MD5 e71dc2fc8a75a20ae3a81da92cd66075
BLAKE2b-256 9179868ab067a87a7e755096fb66fec34686856e8fcc1bb89b92ec7aa935107f

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 487e191077609648802051d8a82702e5eb54b0e6ec005ea8f2c0487deae77db3
MD5 8414275565a76115a8875ebef7360966
BLAKE2b-256 d9597636c5a0a953f52591e716b64fa565a400daa1f0defb4d789b03a08d24ee

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1eb50d50e1d601e458817ce165906b89cd2b6eb4b28183409db7486259a5529f
MD5 87ee1a18fafeaa448cf0040ebaa2a22d
BLAKE2b-256 60fb129b29dd047912529ab7c2d353797d1eaf28fce279e951ba397c95644c79

See more details on using hashes here.

File details

Details for the file neutraltemplate-1.4.0-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for neutraltemplate-1.4.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dac0ec899e4025273fc60c6a40a328444b8684876c23f23e93d8b0f4d232e875
MD5 2a33e7bbb19d4fea3a411c215aee9a28
BLAKE2b-256 e7404c4f296cd708f7f8a3d523a029ef4319ca9b53bd65038e93fa835ba646ae

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