Registry / data / snuggs

snuggs

JSON →
library1.4.7pypypi✓ verified 22d ago

Snuggs is a Python library that provides s-expressions for Numpy, allowing users to define and evaluate array computations using a Lisp-like syntax. It is currently at version 1.4.7 and appears to have a stable, though not frequently updated, release cadence, with the last release in September 2019.

pip install snuggs
INSTALL
IMPORT
SIG · SNUGGS
S
snuggs
datapythonv1.4.7
Install
4.0s avg
Import
505ms
Disk
90MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.508s · 90.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.0s · import 0.502s · 87MB
90MB installed
● package 90MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

snuggs
import snuggs
The primary way to interact with the library is through the top-level 'snuggs' module.

This quickstart demonstrates basic arithmetic operations, array creation using `asarray`, and evaluating expressions with a local context. The `snuggs.eval()` function is central to executing s-expressions.

import snuggs import numpy as np # Basic arithmetic result_add = snuggs.eval('(+ 1 2)') print(f"Addition: {result_add}") # Array creation and multiplication result_multiply_array = snuggs.eval("(* 3.5 (asarray 1 1))") print(f"Multiply with array: {result_multiply_array}") # Evaluation with a local context ctx_array = np.array([2, 2]) result_context = snuggs.eval("(+ (asarray 1 1) b)", b=ctx_array) print(f"With context: {result_context}")
Debug
Known issues
deprecatedThe `kwd_dict` parameter in `snuggs.eval()` is deprecated. Users should pass context variables directly as keyword arguments instead.
fix
Replace `snuggs.eval(expression, kwd_dict={'key': value})` with `snuggs.eval(expression, key=value)`.
affects: 1.4.x and earlier
gotchaSnuggs does not provide performance optimizations like multithreading or elimination of temporary data, unlike libraries such as `numexpr`. It is primarily designed for simple calculator programs.
fix
For performance-critical array computations, consider using libraries explicitly designed for optimized numerical operations or vectorized NumPy code directly, rather than relying on Snuggs for performance gains.
affects: All versions
gotchaWhen using functions or operators that reference the order in which values have been provided within the evaluation context (e.g., 'read' function), it's important to pass a dictionary, specifically an `OrderedDict`, as keyword arguments might not preserve order.
fix
For order-dependent context, create an `OrderedDict` and pass its items as keyword arguments: `ctx = OrderedDict((('a', np.array([5, 5])), ('b', np.array([2, 2])))); snuggs.eval('(- (read 1) (read 2))', **ctx)`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'snuggs'
The `snuggs` library has not been installed in your current Python environment.
fix
pip install snuggs
ValueError: No such operator: <operator_name>
You attempted to evaluate an s-expression containing an operator that has not been defined and added to the `snuggs` instance.
fix
Define the operator using `snuggs_instance.add_op(name, function)` before evaluating expressions that use it.

Example:
```python
import snuggs
import numpy as np
s = snuggs.Snuggs()
s.add_op('add', lambda *args: np.add(*args)) # Define 'add' operator
s.eval_expression('(add 1 2)')
```
sexpdata.SexpdataError: Invalid S-expression at position <N>
The s-expression string passed to `snuggs.eval_expression` is syntactically malformed and cannot be parsed by the underlying `sexpdata` library.
fix
Ensure the s-expression string follows correct S-expression syntax, including proper parenthesization and structure.

Example:
```python
import snuggs
s = snuggs.Snuggs()
# Incorrect: s.eval_expression('add 1 2')
s.add_op('add', lambda a, b: a + b) # Assuming 'add' is defined
s.eval_expression('(add 1 2)') # Corrected with parentheses
```
TypeError: %s() takes from %d to %d positional arguments but %d were given
The s-expression passed an incorrect number of arguments to an operator function (e.g., a wrapped NumPy function or custom lambda) that expects a specific number of positional arguments.
fix
Adjust the s-expression to provide the correct number of arguments required by the operator's underlying function.

Example:
```python
import snuggs
s = snuggs.Snuggs()
s.add_op('sum_two_numbers', lambda a, b: a + b)
# Incorrect (too many arguments): s.eval_expression('(sum_two_numbers 1 2 3)')
s.eval_expression('(sum_two_numbers 1 2)') # Corrected to provide two arguments
```
Upgrade
Version history
1.4.7latest on PyPI · released Sep 18, 2019
Audit
Dependencies
numpyrequiredSnuggs provides s-expressions for Numpy and heavily relies on Numpy arrays and functions for its core functionality.
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources
snuggs — pip install snuggs · libregistry