Skip to main content

pyco-template

  • Fast
  • Simple
  • Easy To Use
  • Lightweight (no more requirements)
  • 尘归尘,土归土,配置归配置,逻辑归逻辑,业务归业务

install

  • pip install pyco-template

usage sample

from pyco_template.ext_json import CoTextTemplate
from pyco_template.ext_json import CoJsonTemplate


def test_text():
    ## NOTE: generally string_format should use `CoTextTemplate`    
    ## NOTE: 注意这种是不适合 CoJsonTemplate, 因为有"{}"
    text = """
    {
      "username": "{name}",
      "password": "{password}",
      "email": "{name}@address.com"
    }
    """
    tpl = CoTextTemplate(text)
    print(tpl)
    txt = tpl.render(password="***")
    print(100, txt)


def test_text2():
    ## NOTE: suggest to use string_template with ${}
    ## NOTE: 这种使用 ${} ,可以使用 CoJsonTemplate 
    text = """
    {
      "username": "${name}",
      "password": "${password}",
      "email": "${name}@address.com"
    }
    """

    tpl = CoJsonTemplate(text)
    txt = tpl.render(password="***")
    print(101, txt)


def test_list1():
    data2 = ["username=${name}", "password=${pwd}"]
    tpl2 = CoJsonTemplate.create(data2)
    txt2 = tpl2.render(pwd="***")
    print(201, txt2)


def test_list2():
    data1 = ["username={name}", "password={pwd}"]
    tpl1 = CoJsonTemplate.create(data1, _used_delimit=False)
    txt1 = tpl1.render(name="developer", ignore_info="this will be ignored!")
    print(202, txt1)


def test_dict1():
    data = dict(
        username="${name}",
        password="${password}",
        email="${name}@address.com",
    )
    tpl = CoJsonTemplate.create(data)
    txt = tpl.render(name="developer")
    print(301, txt)


def test_dict2():
    data = dict(
        username="{name}",
        password="{password}",
        email="{name}@address.com",
    )
    tpl = CoJsonTemplate.create(data, False)
    txt = tpl.render(name="developer")
    tpl.save_file(fout="test_dict.tmp.json")
    print(302, txt)


def test_dict3():
    data = {
        "name": "{topic_name}",
        "sensor": "{sensor_key}",
        "input": "{dataset_dir}",
        "device": "{sdir}",
        "calib_params": "",
        "protocol": {
            "name": "data_proto",
            "version": "{version}"
        },
        "type": "{topic_name}.{type}",
        "elem_count": 0,
        "elem_size": 0,
        "order": "up",
        "data": [
            "{sdir}/{sensor_key}.bin"
        ],
        "index": [
            "{sdir}/{sensor_key}.index.json"
        ]
    }

    tpl_json = CoJsonTemplate.create(data, _used_delimit=False)
    # print(tpl_json)
    kws1 = dict(topic_name="camera", version=2, extra_info="hello")
    txt1 = tpl_json.render(**kws1)
    print(303, txt1)
    tpl_json.save_file(fout="test_dict.tmp.json", **kws1)
    
    tpl2 = CoJsonTemplate.load_file(fout="test_dict.tmp.json")
    print(304, tpl2.render())

Metadata

Release files for pyco-template 0.0.1

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

Source distribution (sdist)

Source distribution for pyco-template 0.0.1
File Size Uploaded Provenance Actions
pyco_template-0.0.1.tar.gz 6.2 kB Without provenance Details for pyco_template-0.0.1.tar.gz

Release files / pyco_template-0.0.1.tar.gz

Download URL pyco_template-0.0.1.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6ff537aeb9fd056eb200ccd3203c42ccc35fd2de78a9f21e60892a9fac792eac
BLAKE2b-256 checksum
How to use checksums
84bba93eab9b0884e731f189d682ae6686ee5a362b12832622c1de97ebac62ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.2

Security for pyco-template 0.0.1

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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file No provenance

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