Skip to main content

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.

Metadata

Release files for pystarlark 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pystarlark 0.0.2
File Size Uploaded
pystarlark-0.0.2.tar.gz 4.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pystarlark 0.0.2
File
pystarlark-0.0.2-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
pystarlark-0.0.2-cp39-cp39-manylinux2010_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.12+ x86-64 Details
pystarlark-0.0.2-cp39-cp39-manylinux1_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.5+ x86-64 Details
pystarlark-0.0.2-cp39-cp39-macosx_10_9_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.9+ x86-64 Details
pystarlark-0.0.2-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
pystarlark-0.0.2-cp38-cp38-manylinux2010_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.12+ x86-64 Details
pystarlark-0.0.2-cp38-cp38-manylinux1_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.5+ x86-64 Details
pystarlark-0.0.2-cp38-cp38-macosx_10_9_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.9+ x86-64 Details
pystarlark-0.0.2-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
pystarlark-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64 Details
pystarlark-0.0.2-cp37-cp37m-manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details
pystarlark-0.0.2-cp37-cp37m-macosx_10_9_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64 Details
pystarlark-0.0.2-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
pystarlark-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64 Details
pystarlark-0.0.2-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details
pystarlark-0.0.2-cp36-cp36m-macosx_10_9_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.9+ x86-64 Details

Total release size: 40.7 MB

Release files / pystarlark-0.0.2.tar.gz

Download URL pystarlark-0.0.2.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
28b8f81fd66ccb182216eebb344946740372af1846c806e17e57cf7ca01833cc
BLAKE2b-256 checksum
How to use checksums
9bc1d67fc5c7b8e339894e89bf368bfd93c38dcd876200cdb93dadc18a3060d0
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp39-cp39-win_amd64.whl

Download URL pystarlark-0.0.2-cp39-cp39-win_amd64.whl
Size 2.5 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
0b2de5fd73878e336290d7acd0ac8affb0aef82b7e54412468be3e572af42488
BLAKE2b-256 checksum
How to use checksums
d848ef287619970842e44068b6302a4d2813a096f701b0b08951bd69d81a1b3e
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp39-cp39-manylinux2010_x86_64.whl

Download URL pystarlark-0.0.2-cp39-cp39-manylinux2010_x86_64.whl
Size 2.5 MB
Tags CPython 3.9 Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
2ac26bb78ced42eb3cc9b09ef84f3390f5311e748754422e2ad1a2b3cb095c0f
BLAKE2b-256 checksum
How to use checksums
686389c2b93ca89b1956d1fa98a0781763963f61f2409d0beccfde30fd065b66
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp39-cp39-manylinux1_x86_64.whl

Download URL pystarlark-0.0.2-cp39-cp39-manylinux1_x86_64.whl
Size 2.5 MB
Tags CPython 3.9 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
ff52ee20369c365b5ca10e701f2bdc1f281f5abd7f1b0d4389b9227937764d56
BLAKE2b-256 checksum
How to use checksums
1cdfae6c3b5da62eb54b1266a5cbff589b22887e02dec7add2ca770e0badb1c4
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp39-cp39-macosx_10_9_x86_64.whl

Download URL pystarlark-0.0.2-cp39-cp39-macosx_10_9_x86_64.whl
Size 2.7 MB
Tags CPython 3.9 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
691e27bae5003564a1c63ce66881676c431719d0fafad6329615147a0fb067ed
BLAKE2b-256 checksum
How to use checksums
0b21746234dda740ac764e49c4234a3f41890651016be05c322226aa63d8d2fa
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp38-cp38-win_amd64.whl

Download URL pystarlark-0.0.2-cp38-cp38-win_amd64.whl
Size 2.5 MB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
de6636e4ff94844745a18d14ee625aad09df314bb6c05815a41a7201a8c555b7
BLAKE2b-256 checksum
How to use checksums
4ff59f100c41ef990b1b0edd4639644dabbe5b96544c4ddb0e29fdeccb99c80e
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp38-cp38-manylinux2010_x86_64.whl

Download URL pystarlark-0.0.2-cp38-cp38-manylinux2010_x86_64.whl
Size 2.5 MB
Tags CPython 3.8 Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
a20860c222b704c3b0f82746ddce2d07d19b23b4ffc4681a6c79544f8a7c5e49
BLAKE2b-256 checksum
How to use checksums
3b20ac1ac58e01cd2b26c7c7b35fdf3e9b2e3f972843a7d2577ecd7259507406
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp38-cp38-manylinux1_x86_64.whl

Download URL pystarlark-0.0.2-cp38-cp38-manylinux1_x86_64.whl
Size 2.5 MB
Tags CPython 3.8 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
43c8301ae7534923adf6b13d5f87f4f438560802bd535e5bd38591ede6559b68
BLAKE2b-256 checksum
How to use checksums
35a509003c47c7a43dd08883fc7067a9da8390c54202185c20d6dd4d85dc4cc5
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp38-cp38-macosx_10_9_x86_64.whl

Download URL pystarlark-0.0.2-cp38-cp38-macosx_10_9_x86_64.whl
Size 2.7 MB
Tags CPython 3.8 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
3aa5a855c1c23d45e906e3790ef9872450e86ffede736c92de98b6b4a1378801
BLAKE2b-256 checksum
How to use checksums
838cd3ec5328ce0db5e853242f3ccabccdc94d27321c10a07827cd7fa1da84a4
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp37-cp37m-win_amd64.whl

Download URL pystarlark-0.0.2-cp37-cp37m-win_amd64.whl
Size 2.5 MB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
d60e2d0faaa34df3411a4c7bba8e841b574ea4ac6282d75905eaf1933b13af00
BLAKE2b-256 checksum
How to use checksums
13fec375dd6e3c88dca01cb63343b6ccf9bc36daae560c430cd3d728bc48735e
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl

Download URL pystarlark-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl
Size 2.5 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
883aee114f186d7668a1bb313998b227802446d031d90b7a63d03be405e5c259
BLAKE2b-256 checksum
How to use checksums
247ebc4cdf9e9cd5426aaa71095e29993b7ad6156f40ada66a54013d548117f3
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp37-cp37m-manylinux1_x86_64.whl

Download URL pystarlark-0.0.2-cp37-cp37m-manylinux1_x86_64.whl
Size 2.5 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
851c80c0f2540b7dd0c57fa860b379851cd7081ee646695c9dcc0cfd963c64a2
BLAKE2b-256 checksum
How to use checksums
4918f1b9b55a7b6dea8c6158533734c3e12781f80cf55f5e69d7c8e019fb4378
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp37-cp37m-macosx_10_9_x86_64.whl

Download URL pystarlark-0.0.2-cp37-cp37m-macosx_10_9_x86_64.whl
Size 2.7 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
105b1ee7a7d24bece9f0c40ccfdaed77af8a12aebde5ef2a59cad27f7ee0dec1
BLAKE2b-256 checksum
How to use checksums
9ff4ead50ea6a5545a0d89bfad731be63460d7c6fcd711422a64d2935a0a98f3
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp36-cp36m-win_amd64.whl

Download URL pystarlark-0.0.2-cp36-cp36m-win_amd64.whl
Size 2.5 MB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
830632547709895f9e80cea23bb012989681cb5aa8fb993747942ca4a1995ba5
BLAKE2b-256 checksum
How to use checksums
41b8cdf80d42162d3e24f67d18f24a4e9a01b4aa26b2bae469fcbb97f8dc5524
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl

Download URL pystarlark-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl
Size 2.5 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
0f2d328b7aababff79c5c648f38f7700fa1b75fe01da74af15aebbb11caf151e
BLAKE2b-256 checksum
How to use checksums
5e41447543b70a835995209801dec6068c50249412731dbc58400ec3257ac5c7
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp36-cp36m-manylinux1_x86_64.whl

Download URL pystarlark-0.0.2-cp36-cp36m-manylinux1_x86_64.whl
Size 2.5 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
4119302b2398a399d7bf50b8906a63be5cbeb46c9bc6d163e678565dc89023aa
BLAKE2b-256 checksum
How to use checksums
81228ee4e365c9bd8db7ce5d36432d69cacca1278ec3dc5c2fcd412ecd14aab5
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pystarlark-0.0.2-cp36-cp36m-macosx_10_9_x86_64.whl

Download URL pystarlark-0.0.2-cp36-cp36m-macosx_10_9_x86_64.whl
Size 2.7 MB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
4930aa353ddb05318d18c9e19ee8432650add9835129a3d57dfa182528e32cf3
BLAKE2b-256 checksum
How to use checksums
9abcff6aa3a0f167ca992658c7bacd570f17f2490cef44c17056dae0b2843c32
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.2 This release

17 release files

0.0.1

13 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page