Skip to content

Releases

0.3.0

Choose a tag to compare

@github-actions github-actions released this 05 Nov 16:10
d818789

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.Steps runs a coroutine that awaits a Request of a transaction, a Command of a program, with its environment and a timeout, a Sleep, and the Steps of another coroutine. run(ua) runs them blocking, in a script, and run_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_p until they end, so the garbage collector does not free them while they wait. (#548)

  • One-liners for YAML and pipes. y of python -m Pyjo loads and dumps YAML, as j does JSON, and s reads the standard input and writes the standard output as bytes, so a one-liner takes what kubectl or 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), and post, put and 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 slurp of Pyjo.File, the configuration plugins and the templates. The parsers of Pyjo.JSON, Pyjo.YAML, Pyjo.INI and Pyjo.TOML take bytes, and load_all gives a Pyjo.Collection. Pyjo.DOM takes the bytes of a page with the encoding that the HTML Living Standard sniffs, and msg.dom() with the charset of Content-Type first, so a page with <meta charset="windows-1250"> is decoded right. (#505, #518, #519)

  • Toolkit.

    • Pyjo.Util has hmac_sha1_bytes, hmac_sha256_bytes and hmac_sha512_bytes, the binary HMAC beside its checksums, as methods of Pyjo.String.Bytes and Pyjo.String.Unicode too. (#526)
    • Pyjo.Date has strftime, and f'{date:%Y%m%dT%H%M%SZ}' formats it, as datetime does. (#528)
    • Pyjo.File has exists, is_file, is_dir and expanduser(), so code with a Pyjo.File needs no os.path. (#530)
  • A certificate of a client. Pyjo/IOLoop/certs has client.crt and client.key beside 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_modules of 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 in asyncio.run or a notebook of Jupyter, where it spun before, and a blocking request there raises RuntimeError: 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, in Pyjo.UserAgent and Pyjo.Server.Daemon, where it was an error of the reactor. (#539)
  • Connections that the server has removed. Pyjo.Server.Daemon discards 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, ConnectionAbortedError of Windows, closes its stream, as a reset one does. Before, the stream emitted an error, which Pyjo.IOLoop.Messages emitted again with no subscriber, so the reactor called the watcher again and again. (#547)
  • Pyjo.Prove on Windows. A report of --formatter on 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.Iterator that ends before its source, as first_p or head, closes its async iterators, which the garbage collector finalized before, with a ResourceWarning on 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. map of Pyjo.Iterator types the values of a coroutine function, and the annotations of object mean builtins.object on 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/Pyjoyment

Full Changelog: 0.2.0...0.3.0

0.2.0

Choose a tag to compare

@github-actions github-actions released this 03 Nov 16:37
ca9d894

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.INI loads and dumps the INI files that well-known programs read and write, as ~/.aws/config and ~/.aws/credentials, php.ini and php-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/config loads the same as botocore reads it. Pyjoyment.Plugin.INIConfig reads the configuration of an application from $moniker.ini, and its sections [plugin Name] load the deployment specific plugins. (#491)

  • Lazy iterators. Pyjo.Iterator iterates an iterable or an asynchronous iterable, with for and async for alike.

    • Its chain of map, grep, uniq, flatten, compact and head passes 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 _p return promises.

    Streams, messages, datagrams and the events of Pyjo.EventEmitter iterate with it. dom.iterate(css) of Pyjo.DOM finds the matches one by one, so first stops the search. i() makes an iterator in the one-liners of python -m Pyjo. (#468, #469, #470)

  • SHA-2 and Base64 for URLs. Pyjo.Util has sha256_bytes, sha256_sum, sha512_bytes, sha512_sum, hmac_sha256_sum and hmac_sha512_sum beside those of SHA-1, and b64url_encode and b64url_decode of RFC 4648 for tokens, signatures and ids in URLs. Pyjo.String.Bytes and Pyjo.String.Unicode have all of them as methods that chain. (#477, #478)

  • Plain log messages. --log-format plain, PYJO_LOG_FORMAT=plain or the attribute plain of Pyjo.Log writes 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) of Pyjo.Test runs 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-only writes function.zip alone, 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 examples lambda_zip, lambda and lambda_stream take 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 a bytearray. Before, they took time in the square of their size: slurp of 50 MB took 1 s, and now takes 8 ms. find of Pyjo.DOM on a large document is 4 times faster, and all_text 14 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, with Invalid 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 event start of the user agent, and the functions of Pyjo.Util in the place of hashlib, hmac and base64. (#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/Pyjoyment

Full Changelog: 0.1.0...0.2.0

0.1.0

Choose a tag to compare

@github-actions github-actions released this 01 Nov 15:15
5b5b954

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 Pyjoyment
from Pyjoyment.Lite import *

get('/', {'text': 'I ♥ Pyjoyment!'})

app.start()

The toolkit: Pyjo

  • HTTP and WebSocket client and server: Pyjo.UserAgent with promises and await, cookies, proxies, SOCKS5, TLS and redirects, and Pyjo.Server.Daemon, with Server-Sent Events and IPv6.
  • The event loop: Pyjo.IOLoop on the asyncio event loop of Pyjo.Reactor.Asyncio, so its I/O and the coroutines and tasks of asyncio share one loop, or on Pyjo.Reactor.Poll without asyncio. 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 ep templates, layouts, template strings and the compression of dynamic responses, sessions, the validator, static files, and Pyjoyment.Lite for a whole application in a single file.
  • Plugins: configuration files in Python, JSON, YAML and TOML, Mount, AllowedHosts against DNS rebinding, and Health for 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, and generate app, lite-app, plugin, pyproject, dockerfile, kubernetes and lambda-zip.

Servers and deployment

  • daemon, prefork, prethread with workers as threads, also on the free-threaded Python, pyjo-hot for deployment without downtime and pyjo-reload for 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 TERM of a container, with a delay before the stop for the readiness probe, and listen on the port of PORT. generate dockerfile writes the image of an application, generate kubernetes its manifests for Kustomize, and generate lambda-zip the 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.md files other agents read too: claude plugin install pyjoyment --marketplace dex4er/Pyjoyment. generate app and generate plugin write an AGENTS.md for 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