Skip to main content

A Tiny file IO utility library for Python powered by Pydantic

Project description

PydanticIO

PydanticIO (pronounce pidantisio) is a tiny file IO utility library for Python powered by Pydantic. This library is a port of the Rust library SerdeIO

Install

# standard distribution
pip install pydanticio

# with YAML backend
pip install pydanticio[yaml]

Supported Formats

  • CSV by stdlib csv module
  • JSON by stdlib json module
  • JSON Lines by stdlib json module
  • YAML by pyyaml library, it is an optional feature and you need enable it manually at when you install it.

Usage

  • read_record_from_reader is used to read a type T which is a subclass of pydantic.BaseModel from TextIO. Data format must be specified by DataFormat literals.
  • read_records_from_reader always tries to deserialize the data as list[T].
  • read_record_from_file and read_records_from_file accepts a Path. Data format is automatically determined by file extension.
  • write_* functions follow the same rules as read_*.

Note that some data format like CSV and JSON Lines support only reading records list[T].

Examples

from pydantic import BaseModel
from pydanticio import read_records_from_file, write_records_to_file

class User(BaseModel):
    name: str
    age: int


users = read_records_from_file("users.csv", User)
write_records_to_file("users.json", users)

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

pydanticio-0.3.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

pydanticio-0.3.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pydanticio-0.3.0.tar.gz.

File metadata

  • Download URL: pydanticio-0.3.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for pydanticio-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ca7b4c64b0bfd33b5b6982df6b85d305d67c8d58c7aa156adff427a61378fc39
MD5 3c9f64b07bd75e456d2b4bc4defa9b1c
BLAKE2b-256 c012324303a9cf091309b59cc0f37aa11bd423d275df1ecd1e869d1a19056817

See more details on using hashes here.

File details

Details for the file pydanticio-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydanticio-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5274daba3ed344bd42ab7f37a7566f229a6273773d34e83f930c1f230715eb7c
MD5 7ee23886b88a4752633be30c8e4c6018
BLAKE2b-256 0ce9aa1d520ae2e39d5a16bafbaf13fbe913aeb84e661d089b26b385b151c646

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