Skip to main content

Python bindings for Starlark in Go

Project description

pystarlark

PyPI

Experimental Python bindings for starlark-go

Installation

pip install pystarlark

Examples

from pystarlark import Starlark

s = 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]

How does this work?

pystarlark is a binding to starlark-go through a shared library built through cgo.

What is Starlark?

Starlark is a Python-like language created by Google for its build system, Bazel. Starlark, while similar to Python, has some features that Python does not. Copied from the main Starlark repo:

Design Principles

  • Deterministic evaluation. Executing the same code twice will give the same results.
  • Hermetic execution. Execution cannot access the file system, network, system clock. It is safe to execute untrusted code.
  • Parallel evaluation. Modules can be loaded in parallel. To guarantee a thread-safe execution, shared data becomes immutable.
  • Simplicity. We try to limit the number of concepts needed to understand the code. Users should be able to quickly read and write code, even if they are not expert. The language should avoid pitfalls as much as possible.
  • Focus on tooling. We recognize that the source code will be read, analyzed, modified, by both humans and tools.
  • Python-like. Python is a widely used language. Keeping the language similar to Python can reduce the learning curve and make the semantics more obvious to users.

In the words of the Starlark developers:

Starlark is a dialect of Python. Like Python, it is a dynamically typed language with high-level data types, first-class functions with lexical scope, and garbage collection. Independent Starlark threads execute in parallel, so Starlark workloads scale well on parallel machines. Starlark is a small and simple language with a familiar and highly readable syntax. You can use it as an expressive notation for structured data, defining functions to eliminate repetition, or you can use it to add scripting capabilities to an existing application.

A Starlark interpreter is typically embedded within a larger application, and the application may define additional domain-specific functions and data types beyond those provided by the core language.

Why would I use this instead of just Python?

Sandboxing

The primary reason this was written is for the "hermetic execution" feature of Starlark. Python is notoriously difficult to sandbox and there didn't appear to be any sandboxing solutions that could run within Python to run Python or Python-like code. While Starlark isn't exactly Python it is very very close to it. You can think of this as a secure way to run very simplistic Python functions. Note that this library itself doesn't really provide any security guarantees and your program may crash while using it (PRs welcome). Starlark itself is providing the security guarantees.

Similar Work

RestrictedPython looks pretty good and would probably work for most use cases including the one that pystarlark was written for. However, Python is notoriously difficult to sandbox and the developers of RestrictedPython even admit that it causes headaches.

The PyPy sandbox would probably work as a secure sandbox but it historically has been unmaintained and unsupported. While some significant work has recently gone into the sandbox, it primarily exists in a seperate branch in the PyPy repo. Also PyPy is a very heavy dependency to bring in if you're already running a Python interpreter.

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

pystarlark-0.0.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distributions

pystarlark-0.0.2-cp39-cp39-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.9 Windows x86-64

pystarlark-0.0.2-cp39-cp39-manylinux2010_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

pystarlark-0.0.2-cp39-cp39-manylinux1_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.9

pystarlark-0.0.2-cp39-cp39-macosx_10_9_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pystarlark-0.0.2-cp38-cp38-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.8 Windows x86-64

pystarlark-0.0.2-cp38-cp38-manylinux2010_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pystarlark-0.0.2-cp38-cp38-manylinux1_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.8

pystarlark-0.0.2-cp38-cp38-macosx_10_9_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pystarlark-0.0.2-cp37-cp37m-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.7m Windows x86-64

pystarlark-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

pystarlark-0.0.2-cp37-cp37m-manylinux1_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.7m

pystarlark-0.0.2-cp37-cp37m-macosx_10_9_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pystarlark-0.0.2-cp36-cp36m-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.6m Windows x86-64

pystarlark-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

pystarlark-0.0.2-cp36-cp36m-manylinux1_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.6m

pystarlark-0.0.2-cp36-cp36m-macosx_10_9_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

Details for the file pystarlark-0.0.2.tar.gz.

File metadata

  • Download URL: pystarlark-0.0.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2.tar.gz
Algorithm Hash digest
SHA256 28b8f81fd66ccb182216eebb344946740372af1846c806e17e57cf7ca01833cc
MD5 e5802646e4e23f602ccaced8fe6d63fb
BLAKE2b-256 9bc1d67fc5c7b8e339894e89bf368bfd93c38dcd876200cdb93dadc18a3060d0

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 0b2de5fd73878e336290d7acd0ac8affb0aef82b7e54412468be3e572af42488
MD5 1d16b6bc68660358183c6e78d5dd0812
BLAKE2b-256 d848ef287619970842e44068b6302a4d2813a096f701b0b08951bd69d81a1b3e

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp39-cp39-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 2ac26bb78ced42eb3cc9b09ef84f3390f5311e748754422e2ad1a2b3cb095c0f
MD5 14b53af1a2107b5f9d03b16223b720bb
BLAKE2b-256 686389c2b93ca89b1956d1fa98a0781763963f61f2409d0beccfde30fd065b66

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp39-cp39-manylinux1_x86_64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp39-cp39-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ff52ee20369c365b5ca10e701f2bdc1f281f5abd7f1b0d4389b9227937764d56
MD5 b8f0c3366026836b0cceeab72be698d1
BLAKE2b-256 1cdfae6c3b5da62eb54b1266a5cbff589b22887e02dec7add2ca770e0badb1c4

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 691e27bae5003564a1c63ce66881676c431719d0fafad6329615147a0fb067ed
MD5 2563fa4d0c4028b2302fed34033cade7
BLAKE2b-256 0b21746234dda740ac764e49c4234a3f41890651016be05c322226aa63d8d2fa

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 de6636e4ff94844745a18d14ee625aad09df314bb6c05815a41a7201a8c555b7
MD5 4bca9602233b18bf245c7cfc180c0c0b
BLAKE2b-256 4ff59f100c41ef990b1b0edd4639644dabbe5b96544c4ddb0e29fdeccb99c80e

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 a20860c222b704c3b0f82746ddce2d07d19b23b4ffc4681a6c79544f8a7c5e49
MD5 a640be7c30938b50b0a2a9e833b746ed
BLAKE2b-256 3b20ac1ac58e01cd2b26c7c7b35fdf3e9b2e3f972843a7d2577ecd7259507406

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 43c8301ae7534923adf6b13d5f87f4f438560802bd535e5bd38591ede6559b68
MD5 ddddd0f99d449b29eb4401158fc23bed
BLAKE2b-256 35a509003c47c7a43dd08883fc7067a9da8390c54202185c20d6dd4d85dc4cc5

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3aa5a855c1c23d45e906e3790ef9872450e86ffede736c92de98b6b4a1378801
MD5 d4f7aa02cf4c5c066c74c37a3b51ca86
BLAKE2b-256 838cd3ec5328ce0db5e853242f3ccabccdc94d27321c10a07827cd7fa1da84a4

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 d60e2d0faaa34df3411a4c7bba8e841b574ea4ac6282d75905eaf1933b13af00
MD5 8888e7c918764cf493574de7c18f758b
BLAKE2b-256 13fec375dd6e3c88dca01cb63343b6ccf9bc36daae560c430cd3d728bc48735e

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 883aee114f186d7668a1bb313998b227802446d031d90b7a63d03be405e5c259
MD5 649ef0191c242bd23f9e30c543e7b2d0
BLAKE2b-256 247ebc4cdf9e9cd5426aaa71095e29993b7ad6156f40ada66a54013d548117f3

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 851c80c0f2540b7dd0c57fa860b379851cd7081ee646695c9dcc0cfd963c64a2
MD5 ce2eacb1ca626e4dfc5e5c46838be7e9
BLAKE2b-256 4918f1b9b55a7b6dea8c6158533734c3e12781f80cf55f5e69d7c8e019fb4378

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 105b1ee7a7d24bece9f0c40ccfdaed77af8a12aebde5ef2a59cad27f7ee0dec1
MD5 b6781056a102ec56c6c84391b374736d
BLAKE2b-256 9ff4ead50ea6a5545a0d89bfad731be63460d7c6fcd711422a64d2935a0a98f3

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 830632547709895f9e80cea23bb012989681cb5aa8fb993747942ca4a1995ba5
MD5 ff489a8d7c1010e7ac8345125baf8227
BLAKE2b-256 41b8cdf80d42162d3e24f67d18f24a4e9a01b4aa26b2bae469fcbb97f8dc5524

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 0f2d328b7aababff79c5c648f38f7700fa1b75fe01da74af15aebbb11caf151e
MD5 4a363c06948d0c7bbf05e39705c07575
BLAKE2b-256 5e41447543b70a835995209801dec6068c50249412731dbc58400ec3257ac5c7

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4119302b2398a399d7bf50b8906a63be5cbeb46c9bc6d163e678565dc89023aa
MD5 353b9d831c36dd92c9db4e62fb89388a
BLAKE2b-256 81228ee4e365c9bd8db7ce5d36432d69cacca1278ec3dc5c2fcd412ecd14aab5

See more details on using hashes here.

Provenance

File details

Details for the file pystarlark-0.0.2-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pystarlark-0.0.2-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.6.1 requests/2.25.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.9

File hashes

Hashes for pystarlark-0.0.2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4930aa353ddb05318d18c9e19ee8432650add9835129a3d57dfa182528e32cf3
MD5 c265ae0bebfea9e86822794b8c2c11aa
BLAKE2b-256 9abcff6aa3a0f167ca992658c7bacd570f17f2490cef44c17056dae0b2843c32

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page