Skip to main content

Python functions for various dict, list, and other data structures.

Project description

datafunc

Python package of various functions for dict, list, and other data structures.

Actively Maintained MIT License PyPI pyversions

Changelog

  • 11/17/2020 - 0.0.4 : Add missing type annotation. Generate docs.
  • 11/17/2020 - 0.0.3 : Added duplicate() and add_sibling() methods. Added some missing type declarations.
  • 11/15/2020 - 0.0.2 : Type annotations & minor refactors.
  • 11/15/2020 - 0.0.1 : Initial methods.

Reference

flatten

flatten(var: object) -> Data

Traverse a dict-like object and return a new one with all the same values but only one layer deep.

Arguments:

  • var: Dict-like variable to flatten.

Returns:

A mo-dots dict-like Data object.

iterable

iterable(var: Any) -> Boolean

Determine whether or not the input variable is iterable.

Arguments:

  • var: Any

Returns:

Boolean

listlike

listlike(var: Any) -> Boolean

Determine if the input variable is list-like (Not a str, not dict-like, but is iterable)

Arguments:

  • var: Any

Returns:

Boolean

mo_dotian

mo_dotian(var: Any) -> Boolean

Determine whether or not the input var is a mo-dots type.

Arguments:

  • var: Any

Returns:

Boolean

apply_if

apply_if(func_to_apply: Callable, var: Any, condition: Callable, else_func: Callable = do_nothing) -> Any

Apply func_to_apply() to var if condiction() else apply else_func()

Arguments:

  • func_to_apply: Callable to pass var to if condition(var) return true
  • var: Variable to test against condition and return through func_to_apply() or else_func()
  • condition: Callable to test var against. Should return a Boolean.
  • else_func: Callable to return var through if condition(var) returns False.

Returns:

func_to_apply(var) if condition(var) returns True, otherwise else_func(var)

dictlike

dictlike(var: Any) -> Boolean

Determine whether or not var is dict-like (Can contain dict-like items).

Arguments:

  • var: Any variable to check

Returns:

Boolean

nestable

nestable(var: Any) -> Boolean

Will return True if input var is either list-like or dict-like.

Arguments:

  • var: Any input variable.

Returns:

Boolean

jsonify_nestable_vals

jsonify_nestable_vals(obj: object) -> Data

Convert any nestable (Dict-like or list-like) to a dict-like mo-dots Data object of obj's values as JSON strings.

Arguments:

  • obj: Any nestable variable.

Returns:

A dict-like mo-dots Data object of obj's values as JSON strings.

compare

compare(d1: object, d2: object) -> Data

Compare dict-like variable d1 to dict-like variable d2 and return a dict-like mo-dots Data object of what's been added, removed, modified, or remained equal in d2

Arguments:

  • d1: Dict-like variable as the base variable.
  • d2: Dict-like variable to compare/contrast to d1

Returns:

Dict-like mo-dots Data object of differences between d1 and d2.

function_of

function_of(func: Callable, func_names: Tuple) -> Boolean

Determine whether or not a function's (func) name exists in tuple of strings (func_names).

Arguments:

  • func: The callable function to test.
  • func_names: Tuple of function names as strings ("func1", "func2", "func3,)

Returns:

Boolean True (func is of func_names) or False (func is not of func_names)

basevals

basevals(var: object, *attrs) -> Any

This method receives a dict and list of attributes to return the innermost value of the given dict-like var. This function seems stupid and I don't recall what it was for.

vivify

vivify(var: object, *attrs: str)

Adds the last attr variable passed to the dict-like "var" in the hierarchy mentioned via the prior *attrs For ex: vivify(animals, "cat", "leg","fingers", 4) is equivalent to animals["cat"]["leg"]["fingers"]=4 This method creates necessary objects until it reaches the final depth This behaviour is also known as autovivification and plenty of implementation are around This implementation addresses the corner case of replacing existing primitives https://gist.github.com/hrldcpr/2012250#gistcomment-1779319

duplicate

duplicate(data: object) -> object

Convenience method for copy.deepcopy()

Arguments:

  • data: Any dict, mo-dots, or dotty object.

Returns:

A deep copy of the data.

add_sibling

add_sibling(data: object, node_path: List, new_key: str, new_data: Any, _i: int = 0)

Traversal-safe method to add a siblings data node.

Arguments:

  • data: The data object you're traversing.
  • node_path: List of path segments pointing to the node you're creating a sibling of. Same as node_path of traverse()
  • new_key: The sibling key to create.
  • new_data: The new data to be stored at the key.
  • _i: Depth of node_path iterator.

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

datafunc-0.0.4.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

datafunc-0.0.4-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file datafunc-0.0.4.tar.gz.

File metadata

  • Download URL: datafunc-0.0.4.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for datafunc-0.0.4.tar.gz
Algorithm Hash digest
SHA256 8fee6985e92105cdb4fce5bbb276b8daac4c6ba55010859431f0c107c629379d
MD5 b8d087c6f75157e3207e5a69b55a7fda
BLAKE2b-256 588b68a05889b1fcb637bfd8c7e13c4c0eb09b9f8f41ec5070020dcc3f4b03cd

See more details on using hashes here.

File details

Details for the file datafunc-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: datafunc-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for datafunc-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f48a2c2849e380d5c1c0ad3004eb7096f998fefe81e3565cfe7356bc618dfbaf
MD5 591cee466fa7bd684d1210f90c71782d
BLAKE2b-256 c71aabc3376ad9b525e76b22655b748dc102111fd8ca621e1cd3d25056340536

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