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.0.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.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pystructs_utils-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 efca228cfce6c76b134b26ed4d3e471bd1df930e989fa655ce7f1aed18fa5ccc
MD5 8092276b941659ebeeba0db85dc65e5f
BLAKE2b-256 dcaf51df06dfb3a0dcf6038b603f547b29c1a696c08b159eed05bf39d10021d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystructs_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99886c576ddbf98e4a3e654980445b121ce3c162f34c81c2682e6aefbf17bddb
MD5 2eec62d9aba9ec6f8e747bb5af2f42d5
BLAKE2b-256 bf2f822a6bcee648b95b24b25bdb20f2b5b1e1382653bd60497e449a354f017e

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