This release is a pre-release and may not be stable for production use.
jqlite for Python
The Python port of jqlite, the profile of the jq language
whose reference implementation is the C# engine in dotnet/JQLite/Core. It
is a 1:1 port, file by file, of that engine (docs/porting.md), proven by the
same conformance corpus (spec/tests). Python 3.11 or later, standard library only.
Use
import jqlite
jqlite.evaluate(".a + 1", {"a": 41}) # [42]
expression = jqlite.parse("[.[] | select(. > $min)]") # parse and bind once
expression.evaluate([1, 5, 10], {"min": 4}) # [[5, 10]], from any thread
# Stream the results, and stop when you have enough (returning False stops; it is not an error).
seen = []
jqlite.parse("range(1000000000)").stream(None, lambda r: seen.append(r) or len(seen) < 3)
# Options: modules, $ENV, clock and zone, the depth limit, debug and stderr handlers.
options = jqlite.Options(
resolver=jqlite.FileResolver("."), # import/include: files relative to the importing one
environment={"HOME": "/home/me"}, # $ENV; None (default) is os.environ
max_depth=1000, # calls of jq functions active at once (spec §11), 0 to 100,000
debug=print, stderr=print,
)
jqlite.parse("$ENV.HOME", options).evaluate(None) # ["/home/me"]
# One evaluation per value of a JSON Lines stream (also evaluate_each_async).
for result in jqlite.evaluate_each(".name", [{"name": "a"}, {"name": "b"}]):
print(result)
try:
jqlite.evaluate("error({code: 1})", None)
except jqlite.JqHaltError as e: # halt_error: e.value, e.exit_code
...
except jqlite.JqParseError as e: # syntax or binding error: e.line, e.column, e.module
...
except jqlite.JqError as e: # uncaught error: e.value; str(e) is spec §10.1's message
...
Values are Python's JSON values, as json.loads gives them. In: int becomes the nearest float,
tuples are lists, any mapping with string keys an object, and a lone surrogate in a string or a key
becomes U+FFFD (§4.1). Out: each value as json.loads would read its canonical text (§5.1): a
number without fraction below 1e21 in magnitude is an int, other numbers are float, NaN is None,
±Infinity is ±1.7976931348623157e+308, and objects keep their key order. Host variables are checked
before evaluation (ValueError for a name that is not an identifier, or ENV). halt ends an
evaluation normally.
The callbacks (stream's, debug, stderr, a resolver's methods) run on the thread that
parses or evaluates: the library starts no thread. max_depth is an int from 0 to 100,000
(jqlite.Options raises ValueError otherwise): 100,000 levels of calls run on a thread with a
256 KB stack and take about 70 MB while they are active (0.7 KB a level).
Importing jqlite changes nothing in the process. While a parse or an evaluation runs, the
library raises Python's recursion limit (sys.setrecursionlimit, a setting of the process) to
what that parse or evaluation may need (spec §11 lets a program meet no recursion limit but
max_depth); when the last parse or evaluation that runs ends, on any thread, the limit is put back
to what it was. The host's own code running meanwhile, its callbacks included, sees the raised limit.
Differences from the .NET API: no resource resolver (the reference's JqResourceResolver reads
.NET embedded resources; implement Resolver to read from package data or anywhere else), no
IObservable evaluation (stream with a callback, evaluate_each and evaluate_each_async cover
streaming), and values are Python's JSON values instead of JsonElement.
Build, test, check
There is nothing to build. From this folder:
python -m unittest # 2,557 tests: the corpus both ways, the unit tests of every layer
python -m compileall -q jqlite tests crossbench.py
python -m mypy # optional tools (pip install mypy ruff), configured in pyproject.toml
python -m ruff check
tests/test_conformance.py: every case ofspec/tests/*.test(read from the shared folder), one test each, through the public API (CorpusPublicApi) and through the core with every prelude builtin bound to its definition (CorpusWithoutNativeOverrides): 1,151 + 1,151 tests.localtime.testruns with a zone fixed at UTC+02:00,modules.testoverspec/tests/modules/.tests/test_catalogue.py: the N and P lists of §9, read from the spec, against the native catalogue and the prelude; the package'sjqlite/prelude.jqagainstspec/prelude.jq.tests/test_values.py,test_syntax.py,test_binding.py,test_runtime.py,test_builtins.py: the reference'sdotnet/Tests/Core/<Layer>tests, ported.test_builtins.pychecks the regex engine against a backtracking matcher of the same programs on random patterns (backtracking_matcher.py,regex_fuzz.py), its linear time and memory, and that it runs the largest programs the limits of §11 allow. It runs 10,000 random patterns per seed (the reference 20,000), shorter linear-time inputs, under the reference's bound of 2 seconds a case, and a shorter input for the program with the most states.tests/test_host.py: the boundary, resolvers, threads, the depth limit through the API.tests/test_portability.py: the portability rules ofAGENTS.mdon the core's code.
jqlite/prelude.jq is a copy of spec/prelude.jq (package data); when the spec's prelude changes,
copy it again (cp ../spec/prelude.jq jqlite/prelude.jq): test_the_embedded_prelude_is_spec_prelude_jq
fails until then.
Benchmark
bench.json runs python crossbench.py <program.jq> <input.json> <take> <warmup-ms> <measure-ms> <output-file> (the protocol of bench/README.md), on the core engine.
pwsh ../bench/run.ps1 -Impl python builds the .NET baseline and runs both.
Layout
Reference (dotnet/JQLite/Core) |
Python (jqlite/) |
|---|---|
Values/*.cs |
values/jq_value.py, jq_array.py, jq_array_builder.py, jq_object.py, jq_object_builder.py, jq_string.py, code_points.py, utf8.py, value_ops.py, value_text.py, errors.py |
Syntax/*.cs |
syntax/token.py, lexer.py, ast.py, parser.py, syntax_error.py |
Binding/*.cs |
binding/bound.py, resolver.py, prelude.py, modules.py |
Runtime/*.cs |
runtime/interpreter.py, env.py, path.py, signal.py, evaluation.py, stack_guard.py, and native_table.py (Builtins/NativeTable.cs, see below) |
Builtins/*.cs |
builtins/natives.py, core_natives.py, loop_natives.py, collection_natives.py, containment.py, string_natives.py, path_natives.py, assign_natives.py, formats.py, math_natives.py, math_extra.py, calendar.py, strftime.py, date_natives.py, regex_syntax.py, regex_engine.py, regex_natives.py, module_natives.py, and registration.py |
the .NET boundary (Jq.cs, JqExpression.cs, …) |
__init__.py (parse, evaluate, evaluate_each), expression.py, options.py, resolvers.py, exceptions.py, json_adapter.py |
Host-specific files (H in the guide), each saying in its header what it uses: values/value_text.py
(repr and float for number text), values/utf8.py (the UTF-8 codec), binding/prelude.py
(importlib.resources), syntax/recursion_limit.py (sys.setrecursionlimit, see The host
stack below) and runtime/stack_guard.py (the frames an evaluation may need),
builtins/math_natives.py (math).
Other host uses in the core, each the counterpart of something every language has:
structinbuiltins/math_extra.py: the bit casts between a double and a 64-bit integer (BitConverter.DoubleToInt64Bitsin the reference) ofnextafterand of exact powers of two.threading.Lock, for what is done once per process or shared between threads, as the reference's locks and static constructors:values/jq_array.py(the claim of a shared buffer's next slot, arrays, objects and strings),binding/prelude.py(the prelude, bound once),builtins/core_natives.py(the list ofbuiltins, computed once),builtins/registration.py(the native table, filled once) andsyntax/recursion_limit.py(the count of the parses and evaluations that run).- The cache of compiled regex programs in
builtins/regex_engine.py, 256 entries emptied when full, as in the reference: adict, whose reads and writes are atomic (the reference's concurrent map).
Differences from the reference's structure
Each is deliberate; the behaviour is the spec's in every case (the corpus runs both ways).
- Values. A value is Python's own
None,bool,float,stror aJqArray/JqObject(guide §2.1), or aJqStringwherevalues/jq_string.pyallows one (see Strings); the engine teststype(v)exactly, soboolis never a number, and nointenters. For a type checkerJqValueisAny: the engine dispatches on a savedtype(v), which checkers do not follow to narrow a union. - Fallible operations return the result or a
Fail(error)(guide §2.2) instead ofbooland twooutparameters. eval_onereturns the output,NOTHING(no output) or aSignal, and leaves the output's path inself.at, instead of the tuple the guide suggests for Python: no allocation per node.NOTHINGis aSignalobject that is never a signal, so one type test tells a value from the rest.- Dispatch by table: the non-tail constructs of
evalandeval_oneare handlers in two lists indexed by node kind (_MANY,_OTHER); the tail positions stay loops, as in the reference. A few fast paths avoid calls without changing the order of evaluation:.nameon the input, a literal or.operand of one operator,as $xbindings andreduce … as $xwithout matching. - Arrays and objects (guide §2.9): the buffer is a growable Python list; the latest version appends in place, the check and the append done under one lock (the reference's compare-and-swap). Every object keeps its key index (a dict shared by the versions of a buffer, extended under the same lock): a dict lookup is faster in Python than the reference's scan of up to 8 keys.
- Strings are Python
str, already code points: no code point map, no UTF-16 ordering fix.sanitizealso joins a high and a low surrogate that a hoststrholds as two code points. A+on strings that gives 256 code points or more makes aJqString(guide §2.9: a buffer ofstrparts, joined once when read), which the next+extends in place, soaddandjoinare linear. Unlike the reference's, it is not a value every part of the engine takes: only the values layer and the interpreter see one, which turns it into astrwhere it enters a container, a native, a template or a format, or reaches the host (the list is invalues/jq_string.py), so the natives and the boundary testtype(v) is stras before.LongStringTestsruns programs through each of those places with every concatenation aJqString; running the whole suite withMIN_LENGTH = 1checks the corpus the same way. - UTF-8 uses Python's codec (
errors="replace"gives one U+FFFD per maximal subpart, as §4.1 says, guide §3.2) instead of the reference's loops. - Sorting uses Python's stable sort (the same order as the reference's stable merge sort, by the
same total preorder), keyed by tuples for scalars and arrays of them, by
compareotherwise. - The JSON reader keeps the reference's algorithm and messages, with fast paths for strings without escapes and for plain integers.
- The native table (guide §1.1) is
runtime/native_table.py, filled bybuiltins/registration.pywhen the package is imported; the formats of §9.9, which the interpreter applies, are reached through it too (native_table.FORMATS), so the runtime does not import the builtins. - Modules:
BindImportsandBindModule, a partial class of the Resolver in C#, are the functionsbind_importsandbind_moduleofbinding/modules.py. - The host stack (guide §3.6): CPython 3.11+ runs Python-to-Python calls without growing the C
stack, and nothing on the recursive paths of the parser, the resolver or the interpreter calls
back into Python through C, so no thread is needed (the reference continues on a fresh thread):
max_depth100,000 runs on a 256 KB thread (test_the_largest_max_depth_runs_on_a_small_stack). What limits depth is the recursion limit, a counter of Python frames:syntax/recursion_limit.pyraises it while a parse, a binding or an evaluation runs and puts it back when the last one ends. A parse needs 8 frames per level of nesting (PARSE_FRAMES); an evaluation 16 frames per node of the bound program (itssize, prelude included) per level ofmax_depth(stack_guard.py), a loose bound that costs nothing until the frames exist. - Regex (guide §3.3): positions are code point indices, since a Python
stris indexed by code point. The engine reads one code point per index (the reference reads a surrogate pair as one), and the natives need no code point map. A pattern that starts with a literal skips to the literal's first occurrence withstr.find, whatever the code point (the reference only for a code point of one UTF-16 unit). The matcher's generation counter is never reset: a Pythonintdoes not overflow. - Math (guide §3.5):
mathraises where IEEE gives a value; each library function checks its domain or catches the overflow and returns the IEEE result.math.fma(3.13+) raises on overflow; there, and before 3.13,fmais computed exactly withfractions.Fraction. s * nfails only past 2^31 − 1 UTF-8 bytes, the spec's limit: Python has no smaller string limit (the reference's .NET limit stops"ab" * 1e9).- Tests left out, because they are about .NET: the size of a value (16 bytes), the culture of
number text (
reprhas none), and the tests of the two .NET APIs this port does not have (JqObservableTests,JqResourceResolver). The allocation measurements ofCollectionTestsandAssignTestsare replaced by structural checks (one buffer shared by 10,000 appends, or by 100,000 string appends) and, for the native_modify, by the growth of its time from 4,000 to 32,000 elements (linear, not quadratic as the prelude's definition, which the test also measures). JqArrayandJqObjecthave no__len__: a value is never tested for truth (an empty array would be false), the engine readscount.
The single-call rule of spec §7.7 and §11 (commit 3074345: Function.single,
CallFunction.single, Native.single_when, the resolver's Defining and replay, eval_one of
calls and closure natives) is ported, with the reference's two unit tests.
Metadata
Release files for devlooped-jqlite 1.0.0a0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| devlooped_jqlite-1.0.0a0.tar.gz | 184.4 kB | With provenance | Details for devlooped_jqlite-1.0.0a0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| devlooped_jqlite-1.0.0a0-py3-none-any.whl | Python 3 | none | any | Details for devlooped_jqlite-1.0.0a0-py3-none-any.whl |
Total release size: 345.0 kB
Release files / devlooped_jqlite-1.0.0a0.tar.gz
| Download URL | devlooped_jqlite-1.0.0a0.tar.gz |
|---|---|
| Size | 184.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8203cc2a33861b09c3833e8c4069e478f5075d9db0d05bb80eaf860e6487bff0
|
|
BLAKE2b-256 checksum How to use checksums |
a3f785d8fd734013e2f3a3a6a858bf7a575763cb76bdd144b55bb708818b93ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logRelease files / devlooped_jqlite-1.0.0a0-py3-none-any.whl
| Download URL | devlooped_jqlite-1.0.0a0-py3-none-any.whl |
|---|---|
| Size | 160.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2c6542e80c00732f6d798e0e0e7e668fcf4e22f0c3e081f7f642e37903d6acd8
|
|
BLAKE2b-256 checksum How to use checksums |
65cfee107469aa31d8023b7d1441885b904e8b216a8c7b2d547d38aaf4d54274
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logSecurity for devlooped-jqlite 1.0.0a0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for devlooped_jqlite-1.0.0a0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.