haip.template
haip.template is Jinja2 based async template rendering module.
Features
- minimalistic: a single exported async function "render"
- autoreturn-type: the return data type is derived from the file suffix
Getting Started
Installing
pip install haip.template
or from source:
git clone https://github.com/haipdev/template.git
Usage
async def render(template_filename, *, template_dir=None, **args)
The template-file is defined by config.template_dir/template_dir/template_filename. **args are used to fillin the placeholders in the template_file and the suffix of the template_file determines the return type. E.g. "template_name.json" will return a json structure (dict). render will propagate exceptions as they are raised by the underlaying modules.
Suffix handling is as follows:
- .json : json struct (dict)
- .sql : string (but **args values will be escaped)
- .* : string
Example
config (using haip.config)
template-dir: /path-to-template-dir/
mytemplate.jinja2
Hello my name is {{ firstname }} {{ lastname }}!
python implementation
import haip.config as config
import haip.template as template
config.load('/path-to-my-config-dir')
document = await template.render('mytemplate.jinja2', firstname='Reinhard', lastname='Hainz')
If mytemplate.jinja is in a subdirectory of the template-dir (e.g. /path-to-template-dir/mysubdir/):
document = await template.render('mytemplate.jinja2', template_dir='mysubdir', firstname='Reinhard', lastname='Hainz')
You can also use absolute paths in the template_dir argument of the render function.
Running the tests
Tests are written using pytest and located in the "tests" directory.
pytest tests
Contributing
Feel free to use and enhance this project. Pull requests are welcome.
Authors
- Reinhard Hainz - Initial work - haipdev
License
This project is licensed under the MIT License - see the LICENSE file for details
Dependencies
Metadata
Release files for haip-template 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| haip-template-0.1.3.tar.gz | 2.7 kB | Without provenance | Details for haip-template-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| haip_template-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for haip_template-0.1.3-py3-none-any.whl |
Total release size: 6.7 kB
Release files / haip-template-0.1.3.tar.gz
| Download URL | haip-template-0.1.3.tar.gz |
|---|---|
| Size | 2.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e3e6dee0897b7158b95c20f096e68fe2ae3c7b9837c0a6046a4f129dfdc321a
|
|
BLAKE2b-256 checksum How to use checksums |
38353be5d531fc24532ce24b403977b6bc68f5d26f9a60d1dfd64a3adea51365
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2
|
Release files / haip_template-0.1.3-py3-none-any.whl
| Download URL | haip_template-0.1.3-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
70237ac3dbeb0c3a9119ff8ff32271f50c63cf4867310f2b27388d4262dfc01b
|
|
BLAKE2b-256 checksum How to use checksums |
61495f6b3dee6491f83c478a26e7985bae80921a7d45b5b0257556f27498c5cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2
|
Security for haip-template 0.1.3
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.