Skip to main content

Functional utilities for nested data structures and validations

Project description

pystructs

pystructs is a lightweight Python library providing functional utilities for working with nested data structures and validations.
Ideal for developers handling JSON, deeply nested dictionaries, or complex data from APIs and databases.


Installation

Clone the repository and install in editable mode:

git clone https://github.com/albertoh88/pystructs.git
cd pystructs
pip install -e .

Modules

1️⃣ Data Structures (pystructs.data_structures)

Functions to manipulate nested lists and dictionaries. Examples:

from pystructs.data_structures import deep_map, merge_deep, pluck_path, filter_deep

data = {"a": 1, "b": {"c": 2, "d": 3}}

# Apply a function to every value
print(deep_map(lambda x: x*10, data))
# Output: {'a': 10, 'b': {'c': 20, 'd': 30}}

# Merge two nested dictionaries
dict1 = {"a": 1, "b": {"c": 2}}
dict2 = {"b": {"d": 3}, "e": 4}
print(merge_deep(dict1, dict2))
# Output: {'a': 1, 'b': {'c': 2, 'd': 3}, 'e': 4}

# Extract nested value safely
print(pluck_path(data, ["b", "c"]))  # 2

# Filter nested structure
nested = {"a": 1, "b": [2, 3, 4]}
print(filter_deep(lambda x: x % 2 == 0, nested))
# Output: {'b': [2, 4]}

2️⃣ Validators (pystructs.validators)

Composable validators to check values and nested structures. Examples:

from pystructs.validators import all_of, any_of, not_fn, is_string, is_number

print(is_string("hello"))  # True
print(is_number(42))       # True

# Combine multiple validators
validate = all_of(is_string, lambda x: len(x) > 3)
print(validate("Test"))    # True

# Negate a validator
negate = not_fn(is_number)
print(negate("abc"))       # True

You can also combine validators with deep_map to validate nested structures.

Benefits

  • Simplifies manipulation of nested data structures in Python.
  • Provides composable functional validators.
  • Ideal for working with JSON, API responses, or complex configs.
  • Lightweight, easy to install and integrate.

Contribution

Contributions are welcome! You can help by:

  • Adding new data structure utilities.
  • Adding more advanced validators.
  • Improving documentation and examples.
  • Writing additional tests. Pull requests are welcome!

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

pystructs_utils-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pystructs_utils-0.1.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file pystructs_utils-0.1.1.tar.gz.

File metadata

  • Download URL: pystructs_utils-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for pystructs_utils-0.1.1.tar.gz
Algorithm Hash digest
SHA256 65e89f3a00c51738bf8d2e4ee5fe9af31ebced8580e4e946d7891dd44017f355
MD5 56f075113b9520759b58fc358ed3da25
BLAKE2b-256 7dce42e233fa9250c4de1532cbe05f759c49cf6599c166bc80ca7a595098581c

See more details on using hashes here.

File details

Details for the file pystructs_utils-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pystructs_utils-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 70a5f505416b65839d6b008124ccd3c644f43455d34fb97d29500320d4602dbf
MD5 2b15c242a58932fe40df9935fb0ea85d
BLAKE2b-256 6085e740c8f475806e3a25b22c0d6d0c1e3e5adf9160eeb6f3b5440d9aa58a74

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page