Library for working with structured data
Project description
Structutils
Structutils is a Python library for working with structured data.
It supports Python 3.14 and later.
Installation
Structutils is available on PyPI under the name pstructutils.
Types
Inferring a type form from a value
import structutils
structutils.infer_type([1, 2, 3]) # => list[int]
Formatting a type form
import structutils
structutils.format_type(list[int]) # => 'list[int]'
Configuration
Creating and validating a schema
import structutils
@dataclass
class User:
age: int
name: str
type Users = list[User]
try:
structutils.check(Users)
except structutils.SchemaError as e:
print(f"Invalid schema: {e}")
Generating a JSON schema from a schema
import structutils
with Path('schema.json').open('w') as file:
json.dump(structutils.generate(Users), file)
Instantiating data using a schema
import structutils
with Path('data.json').open() as file:
raw_data = json.load(file)
try:
data = structutils.instantiate(Users, raw_data)
except structutils.InstantiationError as e:
print(f"Invalid data: {e}")
Miscellaneous
Loading an object from a string specifier
import structutils
pathlib = structutils.load('pathlib', allow_modules=True)
Iterable = structutils.load('collections.abc:Iterable')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pstructutils-1.0-py3-none-any.whl.
File metadata
- Download URL: pstructutils-1.0-py3-none-any.whl
- Upload date:
- Size: 34.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3445d2826078afee71b20e8f56ca2f8d1f1dd5970111483f8f637d92823078a
|
|
| MD5 |
64fb7fc5e5bcab138cdeca571ba5bd86
|
|
| BLAKE2b-256 |
37fd7f0bbc4ca6c7f2e57c93de3cf35b2818f3ecf1698d50b160f71e943d3157
|
Provenance
The following attestation bundles were made for pstructutils-1.0-py3-none-any.whl:
Publisher:
publish.yml on slietar/structutils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pstructutils-1.0-py3-none-any.whl -
Subject digest:
a3445d2826078afee71b20e8f56ca2f8d1f1dd5970111483f8f637d92823078a - Sigstore transparency entry: 1495612125
- Sigstore integration time:
-
Permalink:
slietar/structutils@6755c329e92f29fedbf945ccd34c28186aa7caf0 -
Branch / Tag:
refs/tags/1.0 - Owner: https://github.com/slietar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6755c329e92f29fedbf945ccd34c28186aa7caf0 -
Trigger Event:
push
-
Statement type: