Skip to main content

Yet another typed Python binding to starlark-rust

Project description

星雀 xingque ✨🐦

GitHub Actions Workflow Status PyPI - License PyPI - Version Python Version from PEP 621 TOML PyPI - Implementation PyPI - Format PyPI - Downloads

Yet another Python binding to starlark-rust, exposing the Starlark language to your Python projects. The current version wraps starlark-rust version 0.12.x.

The project's name is a calque of "Starlark" into Chinese. It is pronounced xīng què (in Standard Pinyin) or Hsing-ch'üeh (in Wade-Giles).

The reason behind the curious name

I had to come up with another name for the project after discovering an identically named project after I first renamed the project starlark-pyo3 from python-starlark-rs, and that the probably next-best alternative pystarlark was also taken long ago. Fortunately though, the Chinese name is shorter to type, even shorter than "starlark" itself...

NOTE: this project still has rough corners, do not use in production yet without due care. Expect breaking changes to the API before a 1.0 version.

Features

A fair amount of starlark-rust API has been wrapped so far. You can see the smoke test cases for some examples on how to integrate this package.

This project as compared to other known bindings:

Feature ✨🐦 starlark-pyo3 starlark-go
License Apache-2.0 Apache-2.0 Apache-2.0
py.typed
Binding framework PyO3 PyO3 cgo
ABI3 compatibility ✅ any Python ≥ 3.8
Bundled ✨ Rust, 0.12.x Rust, 0.10.x Go, circa March 2023
Data marshalling ⚡ native FFI 📦 via Python json ⚡ native FFI
Accessing opaque 🐍 values from ✨ 💥 crashes
Accessing opaque ✨ values from 🐍
Magic method proxying for opaque 🐍 values ✅ somewhat complete
Magic method proxying for opaque ✨ values 🔧 WIP
Invoking 🐍 callables from ✨
Invoking ✨ callables from 🐍
Linting 📆 planned
LSP integration 📆 planned
Profiling & code coverage 📆 planned
Structured ✨ documentation 📆 planned

Objects across language boundary

Two-way data marshalling is done natively if a type is available both in Python and Starlark. For complex and/or user-defined types such as classes, opaque wrappers at both sides are available to allow some flexibility -- after all, people would expect some degree of interoperability between Python and Starlark, because Starlark is (arguably) seen by many as a dialect of Python. Opaque Python values in Starlark all have the pyobject type; while opaque Starlark values are starlark.FrozenValue and starlark.Value in Python.

Identity i.e. uniqueness for the underlying concrete objects is NOT preserved for objects across the language boundary: for example, each time you get a plain-old-data value from a FrozenModule a new Python object would be created. This should not cause problems at the Starlark side, as identity comparison (the is operator) is not supported in Starlark anyway, but you should take care at the Python side. Opaque Python values in Starlark context maintain their identities when being read back from Python though, because they are in fact just references to the original object being set.

xingque proxies an opaque Python value's most magic methods into Starlark. This means you can pass your Python objects and callables into Starlark, and use them largely as if the runtime is still Python.

Due to missing API in Starlark and/or PyO3, there can be some operators for whose Python to Starlark proxying is not supported right now. Currently this is:

  • absolute value: Starlark abs(x), Python __abs__: missing StarlarkValue trait method

There are other features that are not implemented right now, but I have plans to support in a future version. These are:

  • slicing i.e. sequence-like usage
  • __{get,set,del}item__ i.e. mapping-like usage
  • iterator protocol

Memory safety

There is no enforced ownership tracking in Python, unlike Rust, so exceptions will be thrown if one tries to use an already consumed object, for example an AstModule already evaluated by an Evaluator.

The starlark::values::Value type does not allow tracking its originating heap in the public API (at least during my investigation while implementing this library), so beware: Python interpreter crashes can occur if a starlark.Value's originating heap is GC-ed but a reference to such a Value is kept elsewhere and later used. More design is needed for fixing the problem; one should expect breaking changes to the API in a future version of this library. Meanwhile, use frozen values and modules whenever appropriate; more determinism can never hurt.

License

Copyright © 2024 WANG Xuerui. All rights reserved.

xingque is licensed under the Apache 2.0 license.

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

xingque-0.2.1.tar.gz (43.7 kB view details)

Uploaded Source

Built Distributions

xingque-0.2.1-cp38-abi3-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.8+ Windows x86-64

xingque-0.2.1-cp38-abi3-win32.whl (2.3 MB view details)

Uploaded CPython 3.8+ Windows x86

xingque-0.2.1-cp38-abi3-musllinux_1_2_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.8+ musllinux: musl 1.2+ x86-64

xingque-0.2.1-cp38-abi3-musllinux_1_2_i686.whl (3.7 MB view details)

Uploaded CPython 3.8+ musllinux: musl 1.2+ i686

xingque-0.2.1-cp38-abi3-musllinux_1_2_armv7l.whl (3.7 MB view details)

Uploaded CPython 3.8+ musllinux: musl 1.2+ ARMv7l

xingque-0.2.1-cp38-abi3-musllinux_1_2_aarch64.whl (3.8 MB view details)

Uploaded CPython 3.8+ musllinux: musl 1.2+ ARM64

xingque-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ x86-64

xingque-0.2.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (4.2 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ s390x

xingque-0.2.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (3.8 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ppc64le

xingque-0.2.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (3.4 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARMv7l

xingque-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARM64

xingque-0.2.1-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl (3.7 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.5+ i686

xingque-0.2.1-cp38-abi3-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

xingque-0.2.1-cp38-abi3-macosx_10_12_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.8+ macOS 10.12+ x86-64

File details

Details for the file xingque-0.2.1.tar.gz.

File metadata

  • Download URL: xingque-0.2.1.tar.gz
  • Upload date:
  • Size: 43.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.7.0

File hashes

Hashes for xingque-0.2.1.tar.gz
Algorithm Hash digest
SHA256 03fcd14b7d9e33f09abb27884b29dd0902b30dafc7710a1fdac83e23b2fbc395
MD5 23a0f88cd1b656dba0a6faccbfb42a34
BLAKE2b-256 fb1d151efa987f1b3b081266ea673351110680be29159cd905d1bc3468dd5751

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for xingque-0.2.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6ad177e50311bd6f646c47882c314113e09ece4bcb9edd7bddf3bdeef30c82ff
MD5 9c8cfd8025a1c1652f8c3821e28c2664
BLAKE2b-256 3cd8510275696bccaf7dc1cee0c23789bb2330b30a8ae32d86c890d0e1063b34

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-win32.whl.

File metadata

  • Download URL: xingque-0.2.1-cp38-abi3-win32.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.7.0

File hashes

Hashes for xingque-0.2.1-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 a78f4fa5ff06109d3de2f9fb71b1ecfa8c3d0969995bb695ccdb98c7a2c59820
MD5 55b98de0a016dd10ea56409e2dc07fdc
BLAKE2b-256 2f711c63a15cc4ca2c7b3e5979fa75d37e3895537245ff57b0b115704ba28f0f

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for xingque-0.2.1-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 819f91c595c236113051f454ed4d20b48663cd79029d4ff6dd1dfc5f709d3116
MD5 34954d82210d71e701b881478ddfba05
BLAKE2b-256 1b20790a3e32ad20101519f8f17ce500de5b2b1783b7e1cd5845057642a04026

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for xingque-0.2.1-cp38-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 73363c7245b0afcd0e027dc5b0fd3cfc9a67b9164ba86acb17c60cc9a24e41d5
MD5 ad9caabab41321045c91f71de82f74ae
BLAKE2b-256 ee93f541c5f6792e8e8ab1248cddc0b92b9e05dfdac0ef7f9d035cded8827a9f

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for xingque-0.2.1-cp38-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 7834d0ca6e4c8e5d5328924de2b2c19f868b907097b7c16bb35ec118f65d6ddf
MD5 3ab4605e64a8e6ef5b111897ad68d026
BLAKE2b-256 43e7b1cb37066198b25a99a2d4e2ea85bcadadd47cec8a53125ed788ae7824fe

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for xingque-0.2.1-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b5782ced27b412d83b6402dc7979e0d5fd19f149d031a067358f62a315704720
MD5 3551829c2976ca1b72ce4bcd31a7d6bc
BLAKE2b-256 8fb7ffeb0ec5a4646d7186fa124b17e06a615f90c9133793ff34defb27c13a27

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for xingque-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7784d9bdf74585c776d0ceb2754fd5423983bd33a41493858c914693d334ce3e
MD5 6ac200a093391cee44b5e93dc82baf60
BLAKE2b-256 082f720be85647b820f11da6d3be1b34d1ecf77f93b804c21b034a177eff3b80

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for xingque-0.2.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 c6e0ec7dde4786f4a8085a61a271198b944bcc97ba0ac05f12cbd804f2a67fd8
MD5 3943787a7b50a3ad37d39c7534972bc4
BLAKE2b-256 acad0665cb16f34e90d9b56a1998b19a6cc5f6cdd9b14c0bbd0933606a5798c4

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for xingque-0.2.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 d4de66132e589135522bcc8254bbd6ccd5903e643de8005faf569b05d72698f1
MD5 c5316ca77347a523561bb1418e12c493
BLAKE2b-256 0b9e55de2663a4646b9f15af0c210394338fb08bd67920d4ff37323c2ee83c2a

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for xingque-0.2.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 f431906a0f13a14bcbec7507490db910964219f4b01f712d742ebd5c483ebdaf
MD5 a7b24c071114f66805000b9c8d3c6a09
BLAKE2b-256 65b6f06ae8350cc0df826fa6150b4da582f3129a865b7496321b643278120a38

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for xingque-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0b02c4e9359b6c3a78e8d172cc5a3b78340a7cd35c0610577be3dd0b9a17f0cc
MD5 b148d0a89a09081272c3514358042d6f
BLAKE2b-256 94d9feb60be6a185bf44ebb41d1084c68b6200868073ee2b42fb3fa9ee815434

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for xingque-0.2.1-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 9fb7eb0ed3d4cd2834852e91d3c935c03d5ba8a118fe09ee523f0bdcf905f6c3
MD5 82701c9c49788f10568fb5f6507cbd76
BLAKE2b-256 692f8c387fbd8ab8322835785107f08e4454d376b1f9e529007181fb81bde28d

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for xingque-0.2.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0f51c06d9ab1d5e91950cb1c3cc9b413b2039ce38e79b059cbeba8e2b17399ab
MD5 5cdfda2fbe28a91aee993e30ddc5aef4
BLAKE2b-256 c5db251615ffa198b6655297ac6117e3784cdbba88777cdd9a65b10848970978

See more details on using hashes here.

File details

Details for the file xingque-0.2.1-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for xingque-0.2.1-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c709b06b35965a5ebad76ffc550ffe7c11c6988d43f079cd0d2799789be117be
MD5 287293603d24d8101512f9e3fa426fc2
BLAKE2b-256 4a0e70b5897e42608fb8be6b93f912f8901c81a7924eeb86f08bf0fc6691723a

See more details on using hashes here.

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