Skip to main content

xju library

Project description

Various modules implemented to some broad principles:

  • fine-grained static typing

  • pure context management

  • useful functionality that is hard to use incorrectly

  • 100% test coverage

(see the bottom of this readme for release history)

xju.newtype - static and dynamic distinct int, float and str types

  • unlike typing.NewType the new types are compatible with isinstance, so you can actually use them to do real stuff, like implement overloaded methods

  • see xju/newtype.py.test for sample code

xju.cmc - context management

  • unlike python standard library e.g. open(), these are “pure” context managers: resources are never acquired until __enter__

xju.cmc.cmclass - provides context management for class attributes that are context managers

  • managing multiple resource attributes is clumsy with ExitStack, this module implements __enter__ and __exit__ automatically to ensure correct ordering and cleanup on exceptions

  • see xju/cmc/cmclass.py.test for sample code

xju.cmc.Dict - dictionary that is a context manager for its (context manager) values

xju.cmc.io - pure context management for e.g. file reading and writing, non-blocking io

xju.cmc.tstore

xju.cmc.perflog

  • time-based json-format record storage built on xju.cmc.tstore

xju.cmc.Thread/Mutex/Lock/Condition

xju.cmc.Task

xju.cmc.AsyncServiceQueue

  • asyncio thread-safe service queue, allows any thread to queue a coroutine on an event loop so it is executed by a task in that event loop

  • see xju/cmc/AsyncServiceQueue.py.test for sample code

xju.pq

  • jquery-like html inspection and modification

  • see xju/pq.py.test for sample code

xju.assert_

  • assert functions that capture term values e.g. x and y in Assert(x)==y

  • see xju/assert_.py.test for sample code

xju.cmd

  • wrapper for subprocess.Popen that captures very common usage without the option-and-flag-warren of subprocess

  • see xju/cmd.py.test for sample code

xju.json_codec

  • encoding/decoding type-hinted dict/list/int/bool/None/float/str and classes to and from json

  • designed to fit well with type checking

  • built in support for xju.newtype described above

  • generates json schema equivalent schemas for types

  • generates typescript code (types, type-guards and dynamic casts) equivalents

  • see xju/json_codec.py.test for full sample code

xju.jsonschema

  • represents JSON schemas as straight-foward, easy-to-read python data structures, because life’s too short for jsonschema.org

  • see xju/jsonschema.py.test for sample code

xju.patch

  • minimal, simple, direct patching(/stub/mock) utility, unlike mock-warren. Because one shouldn’t need a degree to read and write a unit test

  • see xju/patch.py.test for sample code

xju.time

xju.xn

  • Exception wrapping to provide human readable context gathering

  • see xju/xn.py.test for sample code

Release History

  • 1.2.12 fixes typescript null v object handling

  • 1.2.12 adds typescript aliases for NewStr, NewInt, NewFloat

  • 1.2.11 adds typescript –strict support and fixes typescript code generation bugs

  • 1.2.11 xju.json_codec supports Literal[int] and Literal[bool]

  • 1.2.11 xju.json_codec supports generic classes

  • 1.2.10 xju.json_codec supports typing.NewType str/int/bool/float

  • 1.2.9 xju.json_codec generates typescript equivalents

  • 1.2.9 xju.json_codec adds codec() convenience method

  • 1.2.9 xju.json_codec uses kw_args to construct classes

  • 1.2.8 xju.json_codec supports string type-hints (for foward definitions)

  • 1.2.8 xju.json_codec adds typing.Self support (for recursive types)

  • 1.2.8 xju.json_codec requires python 3.11, tested with mypy 1.1.1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xju-1.2.12.tar.gz (74.8 kB view details)

Uploaded Source

Built Distribution

xju-1.2.12-py3-none-any.whl (104.5 kB view details)

Uploaded Python 3

File details

Details for the file xju-1.2.12.tar.gz.

File metadata

  • Download URL: xju-1.2.12.tar.gz
  • Upload date:
  • Size: 74.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for xju-1.2.12.tar.gz
Algorithm Hash digest
SHA256 fd0d1bb1d544643b9f1e2882301cf3273e8ce37ccf6b927d558b6d9aa07664b5
MD5 c5c0fa810699f863ca1b349dcdc454f8
BLAKE2b-256 146e63fddc01dc24cd6b4ab0adf1583e226481fe9020fdf97e53929caa413e35

See more details on using hashes here.

File details

Details for the file xju-1.2.12-py3-none-any.whl.

File metadata

  • Download URL: xju-1.2.12-py3-none-any.whl
  • Upload date:
  • Size: 104.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for xju-1.2.12-py3-none-any.whl
Algorithm Hash digest
SHA256 a22931cc085f1fb69ec156dea869399ef00c7f33594ca5b02c9e2b37b5e7b14c
MD5 a949b56572cd429b5ed55b6045505b40
BLAKE2b-256 df0e3494b06e6ad3064275f4c7862d61a9a7a1bc1397a51b942fa1db234055af

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page