Skip to main content


Project description



pip3 install simpletemplate
from simpletemplate import Template

Template("Hello, {{name}}!").render({'name': 'world'})


%{fields = jclass.fields}%

private {{}}(Builder builder) {
    %{for field in fields:}%
    this.{{}} = builder.{{}};

public static class Builder {

    %{for field in fields:}%
    private {{field.jtype}} {{}} = null;

    %{for field in fields:}%
    %{if field.comment:}%
     * {{field.comment}}
    public Builder set{{}}({{field.jtype}} {{}}) {
        this.{{}} = {{}};
        return this;

    public {{}} build() {
        return new {{}}(this);



def test_template():
    class Obj:

    def jfield(jtype: str, name: str, *, modifier: str = '', init_value: str = '', comment: str = ''):
        field = Obj()
        field.modifier = modifier
        field.jtype = jtype = name
        field.initial_value = init_value
        field.comment = comment

        return field

    data = Obj() = 'ShareConfig'
    data.fields = []
    data.fields.append(jfield('Tencent', 'tencent', modifier='private final'))
        jfield('IWXApi', 'wxApi', modifier='private final', comment='wechat share'))

    print(Template(TMPL_BUILDER).render({'jclass': data}))

if __name__ == '__main__':

generated Java Code

private ShareConfig(Builder builder) {
    this.tencent = builder.tencent;
    this.wxApi = builder.wxApi;

public static class Builder {

    private Tencent tencent = null;
    private IWXApi wxApi = null;

    public Builder setTencent(Tencent tencent) {
        this.tencent = tencent;
        return this;

     * wechat share
    public Builder setWxapi(IWXApi wxApi) {
        this.wxApi = wxApi;
        return this;

    public ShareConfig build() {
        return new ShareConfig(this);

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

simpletemplate-0.0.1b1.tar.gz (3.3 kB view hashes)

Uploaded source

Built Distribution

simpletemplate-0.0.1b1-py3-none-any.whl (3.3 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page