Repository navigation
Releases
0.3.0
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
0.2.0
Pyjoyment 0.2.0 brings INI files, lazy iterators, SHA-2 and Base64 for URLs to the toolkit. It also makes the ZIP files of AWS Lambda reproducible and much smaller with the public layers, and fixes buffers and queues that slowed down with the square of their size.
pip install -U Pyjoyment
uv add 'Pyjoyment>=0.2.0'New
-
INI files.
Pyjo.INIloads and dumps the INI files that well-known programs read and write, as~/.aws/configand~/.aws/credentials,php.iniandphp-fpm.conf. It handles:- sections and keys that keep their case;
- the nested settings of AWS, which load as a dict;
- a key that comes again, which loads as a list;
- quotes, kept by default or taken off with
unquote; - comments, kept with
comments=True, so that a file dumps back as it was.
~/.aws/configloads the same as botocore reads it.Pyjoyment.Plugin.INIConfigreads the configuration of an application from$moniker.ini, and its sections[plugin Name]load the deployment specific plugins. (#491) -
Lazy iterators.
Pyjo.Iteratoriterates an iterable or an asynchronous iterable, withforandasync foralike.- Its chain of
map,grep,uniq,flatten,compactandheadpasses each element on as soon as it has it. map(cb, concurrency=N)takes callbacks that return promises or are coroutines.- Its final methods block, and their forms with
_preturn promises.
Streams, messages, datagrams and the events of
Pyjo.EventEmitteriterate with it.dom.iterate(css)ofPyjo.DOMfinds the matches one by one, sofirststops the search.i()makes an iterator in the one-liners ofpython -m Pyjo. (#468, #469, #470) - Its chain of
-
SHA-2 and Base64 for URLs.
Pyjo.Utilhassha256_bytes,sha256_sum,sha512_bytes,sha512_sum,hmac_sha256_sumandhmac_sha512_sumbeside those of SHA-1, andb64url_encodeandb64url_decodeof RFC 4648 for tokens, signatures and ids in URLs.Pyjo.String.BytesandPyjo.String.Unicodehave all of them as methods that chain. (#477, #478) -
Plain log messages.
--log-format plain,PYJO_LOG_FORMAT=plainor the attributeplainofPyjo.Logwrites a message with its level only, as[info] Hello. This suits a CI log, which adds its own time to each line. (#480) -
Reruns of subtests.
subtest(name, reruns=2, reruns_delay=10)ofPyjo.Testruns a subtest again after a failure. Use it for a test of a remote host when the network fails. Only the last run counts, and the runs before it become diagnostic messages. (#494)
AWS Lambda
- Public layers.
generate lambda-zip --function-onlywritesfunction.zipalone, for the public layers of Python and Pyjoyment that Pyjoyment-Lambda-Layers publishes in the commercial regions of AWS. It reports the layer of Pyjoyment that the function needs. The cookbook explains where to find the ARNs of the layers. The OpenTofu exampleslambda_zip,lambdaandlambda_streamtake the public layers by default. (#487) - Reproducible builds. The bytecode of the ZIP files is the same on every machine and with any number of CPUs, on the free-threaded Python too. (#485, #486)
- Any machine. The generator installs the Python of the target version with uv before it installs the dependencies, so it also works on a machine that does not have that Python. (#473)
Fixes and speed
- Buffers and queues.
Pyjo.File.slurp,Pyjo.Asset.File.slurp,Pyjo.Asset.Memory, the bodies of HTTP messages and the request bodies of the ASGI and WSGI servers grow as abytearray. Before, they took time in the square of their size:slurpof 50 MB took 1 s, and now takes 8 ms.findofPyjo.DOMon a large document is 4 times faster, andall_text14 times. (#475, #476) - Command output. The messages of the commands are flushed at once, so their progress shows as it happens in a pipe, as the log of CI. (#479)
Pyjo.GetOpt. An option whose target is not a list, a dict or a callback fails when it is added, withInvalid option linkage, as in Getopt::Long. Before, it failed only when the option was given. (#482)
The project
- The repository is now pyjoyment/Pyjoyment. The plugin of Claude Code installs with
claude plugin install pyjoyment --marketplace pyjoyment/Pyjoyment. (#464) - The skills for coding agents now cover the log of the application in the place of
print, the commands of an application, the iterators, a signature in the eventstartof the user agent, and the functions ofPyjo.Utilin the place ofhashlib,hmacandbase64. (#477, #478, #479, #482)
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.2.0.tar.gz -R pyjoyment/PyjoymentFull Changelog: 0.1.0...0.2.0
0.1.0
The first release of the revived Pyjoyment: a new port of Mojolicious 9 to Python 3.12 and newer, with asyncio as its event loop and nothing besides the Python standard library. The toolkit and the web framework are ported from Mojolicious 9.53, with its tests, and the API keeps the names of Mojolicious, so its documentation and experience carry over.
pip install Pyjoyment
uv add Pyjoymentfrom Pyjoyment.Lite import *
get('/', {'text': 'I ♥ Pyjoyment!'})
app.start()The toolkit: Pyjo
- HTTP and WebSocket client and server:
Pyjo.UserAgentwith promises andawait, cookies, proxies, SOCKS5, TLS and redirects, andPyjo.Server.Daemon, with Server-Sent Events and IPv6. - The event loop:
Pyjo.IOLoopon theasyncioevent loop ofPyjo.Reactor.Asyncio, so its I/O and the coroutines and tasks ofasyncioshare one loop, or onPyjo.Reactor.Pollwithoutasyncio. TCP, TLS, UDP and UNIX domain sockets, child processes, the standard input and output as a stream of messages, timers, promises and asynchronous iterators. - HTML/XML parser with CSS selectors,
Pyjo.DOM. - JSON with JSON Pointers, JSON Schema from type hints or from a builder after zod, validated against JSON Schema 2020-12, JSON-RPC 2.0 servers and clients over HTTP or any stream, URI Templates of RFC 6570, and YAML and TOML, loaded and dumped.
- Templates with automatic escaping,
Pyjo.Template, and template strings, which take the t-strings of Python 3.14. - Containers for URLs, paths, query strings, headers, cookies and HTTP messages, which convert to and from their counterparts of the standard library.
- Command line options with
Pyjo.GetOpt, also from environment variables, and a logger with JSON Lines for log collectors.
The web framework: Pyjoyment
- Routes with placeholders, types, conditions and nested routes, controllers as classes, the renderer with
eptemplates, layouts, template strings and the compression of dynamic responses, sessions, the validator, static files, andPyjoyment.Litefor a whole application in a single file. - Plugins: configuration files in Python, JSON, YAML and TOML,
Mount,AllowedHostsagainst DNS rebinding, andHealthfor the probes of containers and orchestrators. - Helpers with types for type checkers and editors, and error messages that name the fix of common mistakes.
- The command line interface:
daemon,prefork,prethread,routes,get,eval,inflate, andgenerate app,lite-app,plugin,pyproject,dockerfile,kubernetesandlambda-zip.
Servers and deployment
daemon,prefork,prethreadwith workers as threads, also on the free-threaded Python,pyjo-hotfor deployment without downtime andpyjo-reloadfor development.- An application also runs as an ASGI, WSGI or CGI application, behind FastCGI, and as an event function of AWS Lambda, also streaming its responses.
- Cloud native: the servers stop gracefully on the
TERMof a container, with a delay before the stop for the readiness probe, and listen on the port ofPORT.generate dockerfilewrites the image of an application,generate kubernetesits manifests for Kustomize, andgenerate lambda-zipthe ZIP files of an event function of AWS Lambda.
Mounting other applications
Pyjoyment.Plugin.Mount serves the applications of other frameworks under a path or a host, next to the routes of Pyjoyment: WSGI applications, as those of Flask, ASGI applications, as those of Starlette and the servers of the MCP SDK, with their WebSockets and lifespan, FastCGI applications, as PHP on php-fpm, CGI programs, and event functions of AWS Lambda. An application of another framework can move to Pyjoyment one route at a time.
Tests
Pyjo.Test and Pyjo.Test.Pyjo, inspired by Test::More and Test::Mojo, write test scripts that print TAP, with subtests and chained assertions, and test an application without a server. pyjo-prove runs them in parallel, with reports in JUnit XML and Markdown, and the plugin of pytest runs them too.
Platforms
CPython 3.12 to 3.15, the free-threaded build of 3.15, and PyPy 3.12 on a best-effort basis, on Linux, macOS and Windows, where the servers that fork do not run and prethread runs the workers in threads. The packages are typed, checked with pyright in strict mode.
Documentation and coding agents
- The documentation: the API, ported from the documentation of Mojolicious, and the guides Tutorial, Growing, Routing, Rendering, Mounting, Testing, Cookbook, FAQ and Contributing, whose examples are tested.
- Skills for coding agents, a plugin of Claude Code whose
SKILL.mdfiles other agents read too:claude plugin install pyjoyment --marketplace dex4er/Pyjoyment.generate appandgenerate pluginwrite anAGENTS.mdfor the project.
Supply chain
The wheel and the sdist come with an SBOM in SPDX of the JavaScript libraries that the package bundles, and with attestations of their build provenance, which gh attestation verify checks. They are published to PyPI with trusted publishing and the attestations of PEP 740.
Full Changelog: dex4er/Pyjoyment@0.0.1...0.1.0