{"id":5487,"library":"snuggs","title":"Snuggs","description":"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.","status":"active","version":"1.4.7","language":"en","source_language":"en","source_url":"https://github.com/mapbox/snuggs","tags":["numpy","s-expressions","lisp","numerical-computation"],"install":[{"cmd":"pip install snuggs","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Snuggs provides s-expressions for Numpy and heavily relies on Numpy arrays and functions for its core functionality.","package":"numpy","optional":false}],"imports":[{"note":"The primary way to interact with the library is through the top-level 'snuggs' module.","symbol":"snuggs","correct":"import snuggs"}],"quickstart":{"code":"import snuggs\nimport numpy as np\n\n# Basic arithmetic\nresult_add = snuggs.eval('(+ 1 2)')\nprint(f\"Addition: {result_add}\")\n\n# Array creation and multiplication\nresult_multiply_array = snuggs.eval(\"(* 3.5 (asarray 1 1))\")\nprint(f\"Multiply with array: {result_multiply_array}\")\n\n# Evaluation with a local context\nctx_array = np.array([2, 2])\nresult_context = snuggs.eval(\"(+ (asarray 1 1) b)\", b=ctx_array)\nprint(f\"With context: {result_context}\")","lang":"python","description":"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."},"warnings":[{"fix":"Replace `snuggs.eval(expression, kwd_dict={'key': value})` with `snuggs.eval(expression, key=value)`.","message":"The `kwd_dict` parameter in `snuggs.eval()` is deprecated. Users should pass context variables directly as keyword arguments instead.","severity":"deprecated","affected_versions":"1.4.x and earlier"},{"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.","message":"Snuggs 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.","severity":"gotcha","affected_versions":"All versions"},{"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)`.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}