
Research
NPM targeted by malware campaign mimicking familiar library names
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
Python bindings for go text/template
go_template
works Python 2.7, 3.5, 3.6, 3.7.
pip install go_template
Content of sample.tmpl
{{.Count}} items are made of {{.Material}}
Content of values.yml
Count: 12
Material: Wool
>>> import go_template
>>> go_template.render_template('tests/sample.tmpl','tests/values.yml','')
12 items are made of Wool
>>> import go_template
>>> go_template.render_template('tests/sample.tmpl','tests/values.yml','output.txt')
Content of output.txt
12 items are made of Wool
NOTE: Paths provided to render_template should either be absolute path or relative to directory where it is ran.
For building a fresh shared object of text/template, you must have golang^1.5 installed.
./build.sh
This will create template.so in the bind
folder.
Currently, there is no python package which exposes golang text/template
functionality to python. And I am in the process of learning about interoperability between different languages. So, I started working on this as a learning project.
Golang library cannot be directly used in python. Firstly, we have to compile it as shared object or archive for interoperability with C. And then create python bindings for this C object.
CPython is the original Python implementation and provides cpython API for creating python wrapper, but the wrapping code is in C. There is a library gopy which exactly uses this approach. But it works only on go1.5 and for python2.
If we want to write the wrapping code in python, there are Cython and ctypes. Ctypes allow directly importing the C library and calling functions through its interface. This project uses ctypes
for calling go functions.
When a golang library is compiled as shared object, cgo handles exposing functions and data type conversion. Using ctypes, we can only modify simple data type, string, int, float, bool. I tried converting python class to golang struct, but it failed.
So, I created a golang wrapper over text/template library, which takes simple datatypes. And handles complex operation in this layer. Then a python wrapper over this layer using ctypes
.
It is far from complete and doesn't use the best approach. Currently, it has only one function which takes path of template and value file. And depending on the third argument, either writes to stdout if empty or to file if given its path.
This project is licensed under MIT License.
FAQs
python bindings for go template
We found that go-template demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
Research
Socket's research uncovers three dangerous Go modules that contain obfuscated disk-wiping malware, threatening complete data loss.
Research
Socket uncovers malicious packages on PyPI using Gmail's SMTP protocol for command and control (C2) to exfiltrate data and execute commands.