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.2.0.tar.gz (6.5 kB view hashes)

Uploaded Source

Built Distribution

pydanticio-0.2.0-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page