Skip to main content

Democritus Utility

PyPI CI Lint codecov The Democritus Project uses semver version 2.0.0 The Democritus Project uses ruff to format and lint code License: LGPL v3

Democritus functions[1] for working with utility functions.

[1] Democritus functions are simple, effective, modular, well-tested, and well-documented Python functions.

We use d8s (pronounced "dee-eights") as an abbreviation for democritus (you can read more about this here).

Installation

pip install d8s-utility

Usage

You import the library like:

from d8s_utility import *

Once imported, you can use any of the functions listed below.

Functions

  • def copy_first_arg(func):
        """Decorator to make a copy of the first argument and pass into the func."""
    
  • def has_more_than_one_item(thing: Any) -> bool:
        """Return whether or not the given thing has a length of at least one."""
    
  • def has_one_or_more_items(thing: Any) -> bool:
        """Return whether or not the given thing has a length of at least one."""
    
  • def has_one_item(thing: Any) -> bool:
        """Return whether or not the given thing has a length of at least one."""
    
  • def request_or_read(path):
        """If the given path is a URL, request the URL and return the content; if the path exists read the file.
    
    Otherwise, just return the string and assume it is the input itself."""
    
  • def request_or_read_first_arg(func):
        """If the first arg is a url - request the URL. If it is a file path, try to read the file.
    
    If it is neither a URL nor file path, return the content of the first arg."""
    
  • def is_sorted(iterable, *, descending: bool = False) -> bool:
        """Return whether or not the iterable is sorted."""
    
  • def first_unsorted_value(iterable, *, descending: bool = False) -> Any:
        """Return the first unsorted value in the iterable."""
    
  • def last_unsorted_value(iterable, *, descending: bool = False) -> Any:
        """Return the last unsorted value in the iterable."""
    
  • def unsorted_values(iterable, *, descending: bool = False) -> Iterable[Any]:
        """."""
    
  • def sorted_values(iterable, *, descending: bool = False) -> Iterable[Any]:
        """."""
    
  • def ignore_errors(function, *args, **kwargs):
        """."""
    
  • def zip_if_same_length(*iterables, debug_failure: bool = False):
        """Zip the given iterables if they are the same length.
    
    If they are not the same length, raise an assertion error."""
    
  • def unique_items(iterable_a: Any, iterable_b: Any) -> Dict[str, Set[Any]]:
        """Find the values unique to iterable_a and iterable_b (relative to one another)."""
    
  • def prettify(thing: Any, *args):
        """."""
    
  • def pretty_print(thing: Any, *args):
        """."""
    
  • def subprocess_run(command, input_=None):
        """Run the given command as if it were run in a command line."""
    
  • def stringify_first_arg(func):
        """Decorator to convert the first argument to a string."""
    
  • def retry_if_no_result(wait_seconds=10):
        """Decorator to call the given function and recall it if it returns nothing."""
    
  • def map_first_arg(func):
        """If the first argument is a list or tuple, iterate through each item in the list and send it to the function."""
    
  • def repeat_concurrently(n: int = 10):
        """Repeat the decorated function concurrently n times."""
    
  • def validate_keyword_arg_value(
        keyword: str, valid_keyword_values: Iterable[Any], fail_if_keyword_not_found: bool = True
    ):
        """Validate that the value for the given keyword is in the list of valid_keyword_values."""
    
  • def validate_arg_value(arg_index: StrOrNumberType, valid_values: Iterable[Any]):
        """Validate that the value of the argument at the given arg_index is in the list of valid_values."""
    
  • def wait_and_retry_on_failure(wait_seconds=10):
        """Try to call the given function.
    
    If there is an exception thrown by the function, wait for wait_seconds and try again."""
    

Development

👋  If you want to get involved in this project, we have some short, helpful guides below:

If you have any questions or there is anything we did not cover, please raise an issue and we'll be happy to help.

Credits

This package was created with Cookiecutter and Floyd Hightower's Python project template.

Release files for d8s-utility 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for d8s-utility 0.9.0
File Size Uploaded
d8s_utility-0.9.0.tar.gz 119.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for d8s-utility 0.9.0
File Interpreter ABI Platform
d8s_utility-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 141.8 kB

Release files / d8s_utility-0.9.0.tar.gz

Download URL d8s_utility-0.9.0.tar.gz
Size 119.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9de5433512bf3d78d9b1c6a1323cffbb7dc445e321b83c1ce4d9f4996868128c
BLAKE2b-256 checksum
How to use checksums
99ae5e9f953437b1506f151cd329d8204a5e55135c448b3904fb714f03318040
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 1, 2026.

Transparency log

Release files / d8s_utility-0.9.0-py3-none-any.whl

Download URL d8s_utility-0.9.0-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d06032623158248f198fc41e962ad5895591f45e2158a51fdc468e013adea57d
BLAKE2b-256 checksum
How to use checksums
7dd1cc3a29aba2d00f4be8310afb7114c10e4d8b53196c1f526dd0441a3e4319
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.0

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page