Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/caketop/python-starlark-go
🐍 Python bindings for starlark-go 🐍
https://github.com/caketop/python-starlark-go
python starlark starlark-go
Last synced: 1 day ago
JSON representation
🐍 Python bindings for starlark-go 🐍
- Host: GitHub
- URL: https://github.com/caketop/python-starlark-go
- Owner: caketop
- License: apache-2.0
- Created: 2022-04-13T17:30:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-14T18:26:19.000Z (about 1 month ago)
- Last Synced: 2024-11-12T20:07:10.564Z (2 days ago)
- Topics: python, starlark, starlark-go
- Language: Python
- Homepage: https://python-starlark-go.readthedocs.io/
- Size: 4.18 MB
- Stars: 23
- Watchers: 1
- Forks: 8
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-starlark - python-starlark-go
- awesome-starlark - python-starlark-go
README
# python-starlark-go
[![PyPI](https://img.shields.io/pypi/v/starlark-go)](https://pypi.org/project/starlark-go/)
![Tests](https://github.com/caketop/python-starlark-go/actions/workflows/test.yml/badge.svg)
[![Documentation Status](https://readthedocs.org/projects/python-starlark-go/badge/?version=latest)](https://python-starlark-go.readthedocs.io/en/latest/?badge=latest)
[![action-bumpr supported](https://img.shields.io/badge/bumpr-supported-ff69b4?logo=github&link=https://github.com/haya14busa/action-bumpr)](https://github.com/haya14busa/action-bumpr)## Introduction
This module provides Python bindings for the Starlark programming language.
Starlark is a dialect of Python designed for hermetic execution and deterministic evaluation. That means you can run Starlark code you don't trust without worrying about it being able access any data you did not explicitly supply to it, and that you can count on the same code to always produce the same value when used with the same input data. Starlark was originally created for the [Bazel build system](https://bazel.build/). There are now several implementations of Starlark; this module is built on [starlark-go](https://github.com/google/starlark-go).
This module was originally forked from Kevin Chung's [pystarlark](https://github.com/ColdHeat/pystarlark).
The version of starlark-go that is currently embedded in this module is [v0.0.0-20230302034142-4b1e35fe2254](https://pkg.go.dev/[email protected]).
## Features
- Evalutes Starlark code from Python
- Translates Starlark exceptions to Python exceptions
- Converts Starlark values to Python values
- Converts Python values to Starlark values
- No runtime dependencies - cgo is used to bundle [starlark-go](https://github.com/google/starlark-go) into a Python extension## Installation
```
pip install starlark-go
```## Usage
```python
from starlark_go import Starlarks = Starlark()
fibonacci = """
def fibonacci(n=10):
res = list(range(n))
for i in res[2:]:
res[i] = res[i-2] + res[i-1]
return res
"""
s.exec(fibonacci)
s.eval("fibonacci(5)") # [0, 1, 1, 2, 3]s.set(x=5)
s.eval("x") # 5
s.eval("fibonacci(x)") # [0, 1, 1, 2, 3]
```