Go中Starlark的Python绑定

pystarlark的Python项目详细描述


百灵鸟

PyPI

starlark-go的实验性Python绑定

安装

pip install pystarlark

示例

^{pr2}$

这是怎么回事?在

pystarlark是通过cgo构建的共享库绑定到starlark-go。在

什么是Starlark?在

Starlark是Google为其构建系统Bazel创建的一种类似Python的语言。Starlark虽然与Python相似,但有一些Python没有的特性。从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.

用Starlark开发者的话来说:

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.

为什么我要使用这个而不是Python?在

沙箱

写这篇文章的主要原因是Starlark的“密封执行”特性。众所周知,Python很难进行沙盒,而且似乎没有任何沙盒解决方案可以在Python中运行来运行Python或类Python代码。虽然Starlark并不完全是Python,但它非常接近它。您可以认为这是运行非常简单的Python函数的安全方法。请注意,这个库本身并没有真正提供任何安全保证,您的程序在使用它时可能会崩溃(PRs welcome)。Starlark自己也在提供安全保障。在

类似工作

RestrictedPython看起来不错,可能适用于大多数用例,包括pystarlark为之编写的用例。然而,众所周知,Python很难进行沙盒测试,RestrictedPython的开发人员甚至承认that it causes headaches。在

PyPy sandbox可能是一个安全的沙盒,但它在历史上一直没有被维护和支持。虽然最近有一些重要的工作进入了沙箱,但它主要存在于PyPy回购中的一个独立分支中。另外,如果已经在运行Python解释器,PyPy是一个非常重要的依赖项。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在Android Studio中使用while循环显示包含textview对象的数据   创建名为“userController”的bean时发生java错误:通过字段“userService”表示未满足的依赖关系   java PDFBox PDFImageWrite。writeImage未正确处理所有字符   java无法识别代码中的nzec错误   无法更改java TabLayout字体   在Java中使用子字符串删除部分字符串   Java中的listener addPropertyChangeListener方法   java可以同时拖动多个对象   java如何将数组中的值添加到向量中   java为什么在Camel 3.7.3中无法正确计算属性?   与后端问题不同的机器中的java客户端资源   带字符串的java分割字节数组?   java On_选项_项目_选择的方法说明   java如何在画布的父画中画一个圆?   连接超时和打开连接数的java Netty通道配置   java mysql中如何防止向数据库中插入重复数据   升级到macOS Big Sur后,java无法启动Neo4j控制台应用程序   在Java中使用XSLT将XML转换为HTMLString的ajax   java无法使用Apache POI获取Excel工作表中的数据