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.1.tar.gz (3.2 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.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pydanticio-0.3.1.tar.gz
Algorithm Hash digest
SHA256 d1a8b0dc2c8e6923d5e968c78854fd200db2742f2c0c8aeb162b297f9aded950
MD5 252de257402743385825710f814b98e8
BLAKE2b-256 e124fc609079a1c293272c703c87b8977fec7335a0fa65a5457a2c14c343f235

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pydanticio-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dde3c2babe6d04e07b85dcefda6b5f4e4bbcf4d6b203eef37983c8808cc5c5b8
MD5 801091517de40bdaa022376dfedf985b
BLAKE2b-256 5be8a9830ce80874512735a3c3cabc699039cc1789cfb0dc78b8b6ef7d35c247

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