Pysj makes Python development more comfortable, with utils, classes and helper
Project description
Pysj
This package contains utils, classes and helper functions I find myself reimplementing in several projects. As of now all functions are importable from the top level module.
The name is a commonly used shortened version of the Norwegian word "pysjamas" (in english: pajamas/pyjamas). Coding in your pysjamas/pajamas/pyjamas is comfortable. This package is an attempt to make Python development a bit more comfortable as well.
This is an ongoing project and so far just a few functions are implemented. Most time have been spent on project structure, tests and packaging.
Installation
pip install pysj
Usage
from pysj import sha256, ExtendedJSONEncoder, Timer
# Stopwatch
>>> with Timer():
>>> # Do stuff
>>> sleep(1)
Starting timer
Elapsed time 1.0007134879997466 s.
# Simple hashing
print(sha256("test"))
# JSON Encoder converting datetime to ISO format
json.dumps(
{
"timestamp": datetime.datetime.fromisoformat("2021-12-01T04:50:00.123456")
},
cls=ExtendedJSONEncoder,
)
API Overview
Public classes and functions are importable from the top level package.
Classes
Timer
Simple class working like a stopwatch.
ExtendedJSONEncoder
Subclass for json.JSONEncoder
making encoding of datetime and numpy arrays work.
ExtendedJSONDecoder
Not finished: Subclass for json.JSONDecoder
making decoding of datetime and work.
Functions
flatten
Recursively flattens an iterable (depth first)
seconds
Returns the number of seconds in the given time intervals combined, rounded down to nearest integer.
sha256
Returns the hexdigest representation of the sha256 hash from the plaintext input
sha1
Returns the hexdigest representation of the sha1 hash from the plaintext input
md5
Returns the hexdigest representation of the md5 hash from the plaintext input
uuid
Returns the hex representation of a uuid4 as string
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.