Repository navigation
Pyjoyment 0.3.0 brings Pyjo.Steps, which runs the same code blocking in a script and non-blocking in a server, one-liners for YAML and for the standard input and output, and the encodings of the files that Windows writes and of HTML pages. It also gives the reactors of other distributions what they need to run the whole test suite of Pyjoyment.
pip install -U Pyjoyment
uv add 'Pyjoyment>=0.3.0'New
-
Steps for a script and a server.
Pyjo.Stepsruns a coroutine that awaits aRequestof a transaction, aCommandof a program, with its environment and a timeout, aSleep, and theStepsof another coroutine.run(ua)runs them blocking, in a script, andrun_p(ua)gives a promise, in an action, where the event loop serves the other connections meanwhile. The code of a library that makes requests and runs programs is written once, for both. (#541)async def fetch(ua, url, tries=3): for attempt in range(tries): tx = await Request(ua.build_tx('GET', url)) if tx.res.code != 503: return tx.result.json() await Sleep(0.1 * 2**attempt) data = Steps(fetch(ua, url)).run(ua) # in a script data = await Steps(fetch(c.ua(), url)).run_p(c.ua()) # in an action
The reactor keeps the steps of
run_puntil they end, so the garbage collector does not free them while they wait. (#548) -
One-liners for YAML and pipes.
yofpython -m Pyjoloads and dumps YAML, asjdoes JSON, andsreads the standard input and writes the standard output as bytes, so a one-liner takes whatkubectlor another command prints. The new guide of the one-liners collects them, with PowerShell too. (#502, #511)kubectl get pods -A -o yaml | python -m Pyjo 'c(*y(s()).first()["items"]).map(lambda p: p["metadata"]["name"]).join("\n")' python -m Pyjo 's(y(j(s())))' < config.json > config.yaml
-
Requests as functions.
Pyjo.UserAgent.get(url), andpost,putand the other methods of HTTP, request with a user agent that each thread shares,Pyjo.UserAgent.singleton, so a script needs no user agent of its own. The letters of the one-liners use them. (#517) -
Encodings. A file with a byte order mark, or in UTF-16 as Windows PowerShell writes it, is read as the text it is: by
slurpofPyjo.File, the configuration plugins and the templates. The parsers ofPyjo.JSON,Pyjo.YAML,Pyjo.INIandPyjo.TOMLtake bytes, andload_allgives aPyjo.Collection.Pyjo.DOMtakes the bytes of a page with the encoding that the HTML Living Standard sniffs, andmsg.dom()with the charset ofContent-Typefirst, so a page with<meta charset="windows-1250">is decoded right. (#505, #518, #519) -
Toolkit.
Pyjo.Utilhashmac_sha1_bytes,hmac_sha256_bytesandhmac_sha512_bytes, the binary HMAC beside its checksums, as methods ofPyjo.String.BytesandPyjo.String.Unicodetoo. (#526)Pyjo.Datehasstrftime, andf'{date:%Y%m%dT%H%M%SZ}'formats it, asdatetimedoes. (#528)Pyjo.Filehasexists,is_file,is_dirandexpanduser(), so code with aPyjo.Fileneeds noos.path. (#530)
-
A certificate of a client.
Pyjo/IOLoop/certshasclient.crtandclient.keybeside the certificate of the server, for tests of TLS with a client certificate. The certificates are signed by a new CA,ca.crt, so a trust store that has the old one needs the new one. (#536)
Reactors and event loops
- Reactors of other distributions.
event_loop_modulesof a reactor names the modules of its event loop, as('trio',), so a finalizer of the garbage collector in the middle of the reactor or its event loop defers its cleanup to the next tick, also when the distribution is installed editable. (#534) - asyncio that runs already.
Pyjo.Promise.wait()returns at once in an event loop of asyncio that runs already, as inasyncio.runor a notebook of Jupyter, where it spun before, and a blocking request there raisesRuntimeError: Blocking request in a running event loop. (#522) - Forks. The child of a fork no longer closes the event loop of its parent at its exit. (#499)
Fixes
- Closed connections. A connection that the peer has closed before it is handled has no address,
None, inPyjo.UserAgentandPyjo.Server.Daemon, where it was an error of the reactor. (#539) - Connections that the server has removed.
Pyjo.Server.Daemondiscards the data of a connection that it has removed while its stream still closes, as a pong of a client after the close of a WebSocket, where it was an error of the reactor. (#554) - Aborted connections. A connection that the peer aborted,
ConnectionAbortedErrorof Windows, closes its stream, as a reset one does. Before, the stream emitted an error, whichPyjo.IOLoop.Messagesemitted again with no subscriber, so the reactor called the watcher again and again. (#547) Pyjo.Proveon Windows. A report of--formatteron the standard output is written in UTF-8, as its files are. Before Python 3.15, the encoding of the locale of Windows had no✅of the summary in Markdown, so nothing was written. (#547) A script starts suspended and runs once it is in the job of the harness, so a process that it starts at once ends with it, also through the launcher of a virtual environment, where it could live on, holding the temporary directory of the test. (#556)- Iterators. A chain of
Pyjo.Iteratorthat ends before its source, asfirst_porhead, closes its async iterators, which the garbage collector finalized before, with aResourceWarningon Trio. (#532) - ASGI. The error of an application after it has closed its WebSocket is logged on every reactor of asyncio, also on uvloop. (#510)
- Types.
mapofPyjo.Iteratortypes the values of a coroutine function, and the annotations ofobjectmeanbuiltins.objecton Python 3.14 too, where they meant the class. (#500, #501)
Distributions
The distributions now list the reactors on gevent, Trio, uvloop and Winloop, and Pyjo.AWS and Pyjo.GCP, the clients of the APIs of Amazon Web Services and Google Cloud without an SDK, which are on their way to their first releases. (#542)
The skills for coding agents now cover Pyjo.Steps, the functions of the user agent and the encodings of pages. (#541, #517, #519)
Supply chain
The wheel and the sdist come with an SBOM in SPDX and with attestations of their build provenance:
gh attestation verify pyjoyment-0.3.0.tar.gz -R pyjoyment/PyjoymentFull Changelog: 0.2.0...0.3.0