A library of tiny little functions to help do more while doing less.
Project description
diogi
Diog means to laze in Welsh. This package is to help me do less.
Most of the functions and decorators included in the diog package
could be easily implemented with a single line of obscure python
but then I would have to implement (and test) them again and again.
I'd rather not. I'm lazy.
Functions
always_a_list(obj: any) -> list with alias aal
takes any object and if it isn't a list already, it wraps it up in one.
It is also available as @always_a_list decorator.
default_if_none(obj: any, default: any) -> any: with alias din
acts as a null coalescence.
first_or_default(lst: list, default: any=None) -> any: with alias fod returns the first element of a list
if there is at least one element, or the default value.
get_if_exists(obj: any, key: str, default: any=None) -> any with alias gie.
attempts to get a property of a dictionary or an attribute of an object, and if it doesn't exist or is None the default value is returned.
list_is_optional(obj: any) -> any with alias lio
takes any object and if it is a list with a single element
then it returns just the element, otherwise the list is returned.
It is also available as @list_is_optional decorator.
list_without_nones(lst: list) -> list with alias lwn
returns copy of the list without any None values.
It is also available as @list_without_nones decorator.
none_if_empty(obj: any) -> any with alias nie
returns copy of the object unless it is an empty list or an empty directory
append_if_not_none(obj: any, value: any, key: str) -> any with alias ainn
get_if_exists(obj: any, key: str) -> any with alias gie
set_if_not_none(obj: any, value: any, key: str) -> any with alias sinn
Conventions
to_data sometimes the object needs to be converted to a simpler data
representation of dicts and lists. In those cases my objects implement
a public method as_data(self). The diog.conventions.to_data(obj: any)
takes an object or a list of object, and reduces the input to data.
Development
This repository uses uv for environment and dependency management.
Install the project and development dependencies:
uv sync --group dev
Run the test suite:
uv run pytest
Build the source distribution and wheel:
uv build
To Publish
uv sync --group dev
uv run pytest
uv build
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.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file diogi-0.1.1.tar.gz.
File metadata
- Download URL: diogi-0.1.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
289dab3f921c6d903e481bbce83c01459444b14d9f7cca88f29f75e9491a9a84
|
|
| MD5 |
f69bc8a501349c7371f505e04b2ce851
|
|
| BLAKE2b-256 |
cb2921be9e4964fff74ae4bf4dca002d9a9574e75e78fcbb743fe7a17f746c6a
|
Provenance
The following attestation bundles were made for diogi-0.1.1.tar.gz:
Publisher:
build.yml on michalporeba/diogi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
diogi-0.1.1.tar.gz -
Subject digest:
289dab3f921c6d903e481bbce83c01459444b14d9f7cca88f29f75e9491a9a84 - Sigstore transparency entry: 1122500357
- Sigstore integration time:
-
Permalink:
michalporeba/diogi@7651861fe908f195a122064360dd98470091f8ff -
Branch / Tag:
refs/heads/main - Owner: https://github.com/michalporeba
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@7651861fe908f195a122064360dd98470091f8ff -
Trigger Event:
push
-
Statement type:
File details
Details for the file diogi-0.1.1-py3-none-any.whl.
File metadata
- Download URL: diogi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96729cf4c86d26eca7f9c503cbb178f5f37ba13995bb5ce53b22d75f5bea8893
|
|
| MD5 |
317189eed3e7aa423e0fd9f15904179d
|
|
| BLAKE2b-256 |
de8b6213a9c5e658e471bcbb10e816598108fa98b6297758d601305e53a980f8
|
Provenance
The following attestation bundles were made for diogi-0.1.1-py3-none-any.whl:
Publisher:
build.yml on michalporeba/diogi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
diogi-0.1.1-py3-none-any.whl -
Subject digest:
96729cf4c86d26eca7f9c503cbb178f5f37ba13995bb5ce53b22d75f5bea8893 - Sigstore transparency entry: 1122500365
- Sigstore integration time:
-
Permalink:
michalporeba/diogi@7651861fe908f195a122064360dd98470091f8ff -
Branch / Tag:
refs/heads/main - Owner: https://github.com/michalporeba
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@7651861fe908f195a122064360dd98470091f8ff -
Trigger Event:
push
-
Statement type: