Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PyStructs Utils – Functional utilities for nested Python data structures and validations (deep merge, map, filter, path extraction).

License

NotificationsYou must be signed in to change notification settings

albertoh88/pystructs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

pystructs is a lightweight Python library providingfunctional 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.gitcd pystructspip 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_deepdata = {"a": 1,"b": {"c": 2,"d": 3}}# Apply a function to every valueprint(deep_map(lambda x: x*10, data))# Output: {'a': 10, 'b': {'c': 20, 'd': 30}}# Merge two nested dictionariesdict1 = {"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 safelyprint(pluck_path(data, ["b","c"]))# 2# Filter nested structurenested = {"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_numberprint(is_string("hello"))# Trueprint(is_number(42))# True# Combine multiple validatorsvalidate = all_of(is_string, lambda x: len(x)> 3)print(validate("Test"))# True# Negate a validatornegate = 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!

About

PyStructs Utils – Functional utilities for nested Python data structures and validations (deep merge, map, filter, path extraction).

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2026 Movatter.jp