Skip to main content

Democritus functions for working with utility functions.

Project description

Democritus Utility

PyPI CI Lint codecov The Democritus Project uses semver version 2.0.0 The Democritus Project uses black to format 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.

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

d8s_utility-0.8.0.tar.gz (29.7 kB view details)

Uploaded Source

Built Distribution

d8s_utility-0.8.0-py2.py3-none-any.whl (25.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file d8s_utility-0.8.0.tar.gz.

File metadata

  • Download URL: d8s_utility-0.8.0.tar.gz
  • Upload date:
  • Size: 29.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for d8s_utility-0.8.0.tar.gz
Algorithm Hash digest
SHA256 ac1a93052b93275ef9a6c71e9c2d5d22a7fb55429083f8ac616d7dfa4af12b58
MD5 3c7f7f95688482abb74a02848bc6dbfb
BLAKE2b-256 01a7189d631779a1a5bd682c7ec10e2d9364269641bdcb837ab77ef2c8807b44

See more details on using hashes here.

File details

Details for the file d8s_utility-0.8.0-py2.py3-none-any.whl.

File metadata

  • Download URL: d8s_utility-0.8.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for d8s_utility-0.8.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fc76c931ed3f6cafb855d6aba33a5d1b418c7c53e3ec99f4c1e165e87f520a5f
MD5 1999750fb2d4c65c59180a7af417cf36
BLAKE2b-256 423ff96d72bd6d4ae1120ffc4c2801da28ada3a95d6f4ad4f90c2262e63e828a

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