Unified I/O interface for Python
Project description
⚡️ Introduction
unified-io is a Python utility that attempts to unify several I/O operations (i.e., read/write data in different formats) under a similar interface while making them more concise and user-friendly.
The library provides a unified interface for reading/writing files, which is based on the following principles:
- Read/write interfaces consist of concise functions with similar signatures.
- Read/write interfaces allows passing keyword arguments to the underlying I/O functions to preserve flexibility.
- Read operations can be performed lazily using generators.
- Before reading/writing, the user can specify a callback function that will be applied to each element of the data stream.
- read functions have load aliases (e.g.,
read_csv
has aload_csv
alias) and write functions have save aliases (e.g.,write_csv
has asave_csv
alias. - Use very efficient stuff for each format (e.g.,
orjson
forjson
files). Suggestions are welcome!
✨ Supported formats
🔌 Requirements
python>=3.7
💾 Installation
pip install unified-io
💡 Examples
The API is designed to be as simple as possible. For example, the following code snippet reads a CSV file, applies a callback function to each element of the data stream, and writes the result to a JSONl file:
from unified_io import read_csv, write_jsonl
def callback(x):
return {"id": x["id"], "title": x["title"].lower()}
# Using a generator we avoid loading the entire file into memory
data = read_csv('input.csv', callback=callback, generator=True)
write_jsonl('output.jsonl', data)
📚 Documentation
Browse the documentation for more details and examples.
🎁 Feature Requests
Would you like to see other features implemented? Please, open a feature request.
🤘 Want to contribute?
Would you like to contribute? Please, drop me an e-mail.
📄 License
unified-io is an open-sourced software licensed under the MIT license.
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
Built Distribution
File details
Details for the file unified-io-0.1.0.tar.gz
.
File metadata
- Download URL: unified-io-0.1.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87eee20cbdefde6143598ffeeb74cb8ff256f73bf69785d5eb76947dedb03a76 |
|
MD5 | 38b79795b1a8db8326c213d6dad1c617 |
|
BLAKE2b-256 | a6de1c95c9be397e2dd5658a6bc638b8e5f5a2691f4030ffff8ca4206759f04b |
File details
Details for the file unified_io-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: unified_io-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18d82ff7bc1c2d7b005d463b50ad01294e32fb50d9b5aba8b692087a7376efc2 |
|
MD5 | cf2b1e6b4c20b22b5f84374650a5b8c4 |
|
BLAKE2b-256 | 919a1022038f7ff6d3563a28ebe046c07dcce2712f02d4e3e849979a4e04a9b6 |