Registry / serialization / sexpdata

sexpdata

JSON →
library1.0.2pypypi✓ verified 84d ago

A simple S-expression parser for Python, supporting both parsing and serialization of S-expressions. Current version is 1.0.2, released January 2023. Development is active but releases are infrequent.

pip install sexpdata
INSTALL
IMPORT
SIG · SEXPDATA
S
sexpdata
serializationpythonv1.0.2
Install
1.5s avg
Import
17ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.2 · 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.010s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.010s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

loads
from sexpdata import loads
import sexpdata; sexpdata.loads()
loads is a top-level function, not a method of the module; direct import is idiomatic.
dumps
from sexpdata import dumps
import sexpdata; sexpdata.dumps()
Same as loads.

Basic parsing and serialization of an S-expression string.

from sexpdata import loads, dumps sexp_str = '(foo (bar 1 2) "string" nil)' parsed = loads(sexp_str) print(parsed) # Output: [Symbol('foo'), [Symbol('bar'), 1, 2], 'string', Symbol('nil')] # Serialize back sexp_out = dumps(parsed) print(sexp_out) # Output: (foo (bar 1 2) "string" nil)
Debug
Known issues
gotchasexpdata does not handle nil consistently; nil is parsed as Symbol('nil'), not Python's None. Comparison with None will fail. Use Symbol('nil') or check with .lower() if needed.
fix
Check for Symbol('nil') explicitly: from sexpdata import Symbol; if val == Symbol('nil'): ...
affects: all
gotchaParsing returns a list for the top-level S-expression, not a single element. A single atom like '42' will return a list containing the atom: [42]. This is different from some other parsers.
fix
If expecting a single atom, index into the result: parsed[0].
affects: all
Errors
Common errors & fixes
AttributeError: module 'sexpdata' has no attribute 'loads'
Importing incorrectly (e.g., import sexpdata then sexpdata.loads). Actually loads is a top-level function; you must import it directly.
fix
Use: from sexpdata import loads
ValueError: malformed S-expression at line 1
Input string is not properly formatted S-expression (e.g., missing closing parenthesis, stray characters).
fix
Ensure the input is valid S-expression. Validate with a validator or use a try/except block.
TypeError: expected string or bytes-like object
Passing a non-string (e.g., integer) to loads().
fix
Convert the argument to str: loads(str(my_var))
Upgrade
Version history
1.0.2latest on PyPI · released Jan 9, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Resources
sexpdata — pip install sexpdata · libregistry