Utilities
In any project we usually need a set of functions that we use again and again and that don’t typically belong to the project. They go in an util file because they do not belong to the specific application logic. We also spend time in every project searching, adapting and copy/pasting these functions.
In this project, I, decided to collect those functions and put them in one centralized place!
Functionalities
Utilities libprary is broken up into broad domains of functionality in orther to easily remember where thinks are located.
Dictionnaries
DotDict
enum
Python doesn’t have a built-in way to define an enum, so this module provides (what I think) is a pretty clean way to go about them.
from utils import enum
class ModelTypes(enum.Enum):
CLASSIFICATION = 0
REGRESSION = 1
# Defining an Enum class allows you to specify a few
# things about the way it's going to behave.
class Options:
frozen = True # can't change attributes
strict = True # can only compare to itself; i.e., Colors.RED == Animals.COW
# will raise an exception.
Once defined, use is straightforward:
>>> ModelTypes
dicts
intersections, differences, winnowing, a few specialized dicts…
lists
flatten and unlisting. also flat_map!
bools
currently only provides an xor function.
dates
objects
provides get_attr, which is really just a convenient way to do deep getattr chaining:
>>> get_attr(complicated, 'this.is.a.deep.string', default=None)
"the deep string" # or None, if anything in the lookup chain didn't exist
There’s also an immutable utility, which will wrap an object and preven all attribute changes, recursively by default. Any attempt to set attributes on the wrapped object will raise an AttributeError:
>>> imm = immutable(something)
>>> imm
<Immutable Something: <Something>>
>>> imm.red
<Immutable SomethingElse: <SomethingElse: red>>
>>> imm.red = SomethingElse('blue')
# ...
AttributeError: This object has been marked as immutable; you cannot set its attributes.
>>> something.red = SomethingElse('blue')
>>> imm.red
<Immutable SomethingElse: <SomethingElse: blue>>
You can toggle the recursive immutability by specifying the ‘recursive’ flag.
Installation (via pip)
pip install kdmt
Metadata
Release files for kdmt 1.0.73
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kdmt-1.0.73-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for kdmt-1.0.73-py2.py3-none-any.whl |
Release files / kdmt-1.0.73-py2.py3-none-any.whl
| Download URL | kdmt-1.0.73-py2.py3-none-any.whl |
|---|---|
| Size | 443.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
535117a235b2e8faa4389949a5ddece3277ba3e97c46eb74270972fa3fcb3788
|
|
BLAKE2b-256 checksum How to use checksums |
945847debd042c2807623880467c6ef6d69d73759edaa8d3871802906e850440
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.11
|
Security for kdmt 1.0.73
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.