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 typeT
which is a subclass ofpydantic.BaseModel
fromTextIO
. Data format must be specified byDataFormat
literals.read_records_from_reader
always tries to deserialize the data aslist[T]
.read_record_from_file
andread_records_from_file
accepts aPath
. Data format is automatically determined by file extension.write_*
functions follow the same rules asread_*
.
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
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 Distribution
pydanticio-0.2.0.tar.gz
(6.5 kB
view details)
Built Distribution
File details
Details for the file pydanticio-0.2.0.tar.gz
.
File metadata
- Download URL: pydanticio-0.2.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b430279174380e2e53ea5ed931697bfa82cfeeca80ea2b4fa337eb29cea5f2da |
|
MD5 | 416319843182471cecd837555ef93cf8 |
|
BLAKE2b-256 | bcfd0772e4d9cf9c62d095ecb6a58f1b32802835d68ce7401b510f69182e856a |
File details
Details for the file pydanticio-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: pydanticio-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 810b3f24b1fb1fc718727a9348b213e0534aa0014ef6549b69c89622c6e92e78 |
|
MD5 | 763920c50416e84c61e5777638c89c5e |
|
BLAKE2b-256 | 2cc6277c7b214a8812c964dc3f4b37652d69a9bd066008234218a31050397e5a |