A Jinja2 template loader for AWS S3.
Project description
Project Status: Beta. It’s pretty simple and works for me, but not heavily tested in production use. Caveat Emptor.
Usage
This library relies on the boto3 library for S3 access, so you will need to configure your AWS credentials first. Then, provide your S3 bucket name and optional template directory name when instantiating the loader:
#!python from jinja2 import Environment from jinja2_s3loader import S3loader s3template_dir = "test/templates" # trailing slash not required, but ok j2 = Environment(loader=S3loader('my-s3-bucket-name', s3template_dir)) t = j2.get_template('mytemplate.j2') # loads test/templates/mytemplate.j2 print(t.render({}))
Note that, although S3 does not have real directories and treats the prefix string as purely a sub-string, this S3loader will treat the prefix as a subdirectory. That is, it will add a trailing slash if none is provided.
Remember, accessing files over S3 costs money. The loader currently does not support live reloading. I built this to support accessing S3 templates from AWS Lambda functions, so those constraints are fine with me, but your use case may be different.
Contributions welcome. File a Github issue to report a bug.
Known Issues
The loader blindly attempts to decode all templates as UTF-8. If your template is encoded with an incompatible encoding, it WILL be broken. PR’s welcome.
License
Copyright 2015 Vince Veselosky and contributors.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file jinja2_s3loader-0.3.0.tar.gz
.
File metadata
- Download URL: jinja2_s3loader-0.3.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86f305bec5936a85b1c9ef926e2809b2004fd5c9aba04a6597fc71126a300c7d |
|
MD5 | a1a249eedf412e083495f3c4d1c6cf17 |
|
BLAKE2b-256 | eab40003d70404e3242b9be2d196d50eac0a7d8174b1610b95a74b8903a130c2 |
File details
Details for the file jinja2_s3loader-0.3.0-py2.py3-none-any.whl
.
File metadata
- Download URL: jinja2_s3loader-0.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27d2b34217056cf0a8f85d7628d84858860b5355176808d5f4fa490fa3670b1c |
|
MD5 | c971f0088191eff7ac208eb2090523a4 |
|
BLAKE2b-256 | 326bdad91b62c8e23c56f16a36d9145652d7a5c4fe561c3a8f6154fd4307216c |