Skip to main content

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

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

pstructutils-1.0-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

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

Hashes for pstructutils-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3445d2826078afee71b20e8f56ca2f8d1f1dd5970111483f8f637d92823078a
MD5 64fb7fc5e5bcab138cdeca571ba5bd86
BLAKE2b-256 37fd7f0bbc4ca6c7f2e57c93de3cf35b2818f3ecf1698d50b160f71e943d3157

See more details on using hashes here.

Provenance

The following attestation bundles were made for pstructutils-1.0-py3-none-any.whl:

Publisher: publish.yml on slietar/structutils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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