Skip to main content

Abara File IO

Description

Pythonのローカルファイルの読み書きを、細々とした設定なしに最適な方法で実行するライブラリ。

text、ini、json、yaml、tomlに対応。

読み込み時は自動的に文字コードを判定。
書き込み時は常に文字コード UTF-8 、改行コード \n を使用。

Dependency

tomli-w

ruamel.yaml

charset-normalizer

Install

pip

pip install abara-file-io

uv

uv add abara-file-io

Usage

ファイルの読み込み

ファイルを読み込む場合はread_から始まる関数を使用する。

from abara_file_io import read_text, read_ini, read_json, read_yaml, read_toml

path = './parent/stem.suffix'

text_response: str = read_text(path)

ini_response: dict = read_ini(path)

json_response: dict = read_json(path)

yaml_response: dict = read_yaml(path)

toml_response: dict = read_toml(path)

読み込みは第1引数にファイルのパス( str か、pathlibの Path オブジェクト)を指定するだけで動作する。

エンコードは最初に UTF-8 を試し、違った場合はcharset-normalizerで自動的に判定して読み込むので煩わされる必要がない。

読み込み時に存在しないファイルパスを指定などしてエラーが出た場合もエラーで停止しない仕様。
その場合は空の str もしくは dict を返すので、必要に応じて処理を分岐させることができる。

ファイルの書き込み

書き込む場合はwrite_から始まる関数を使用する。

from abara_file_io import write_text, write_ini, write_json, write_yaml, write_toml

path = './parent/stem.suffix'

str_data = 'Beautiful is better than ugly.'

dict_data = {'foo': 'bar', 'baz': 'qux'}

write_text(str_data, path)

write_ini(dict_data, path)

write_json(dict_data, path)

write_yaml(dict_data, path)

write_toml(dict_data, path)

書き込みは第1引数に書き込むオブジェクト。
第2引数に保存するファイル拡張子まで含めたパス( str か、pathlibの Path オブジェクト)を入れる。

常に文字コード UTF-8 、改行コード \n で保存されるのでWindowsで指定を忘れてしまうことがなく安全。
拡張子を .bat と .cmd にした場合のみ、 UTF-8 では動作しないため自動的にShift-JIS( CP932 )と \r\n で保存される。

書き込みに保存先パスの指定ミス等で処理が失敗してもエラーで停止しない仕様。
もし失敗時に何をさせたい場合、全ての関数は書き込みに成功したら True 、失敗したら False を返すので、必要に応じて処理を分岐させることができる。

Licence

MIT

Metadata

Release files for abara-file-io 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for abara-file-io 1.0.1
File Size Uploaded Provenance
abara_file_io-1.0.1.tar.gz 14.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for abara-file-io 1.0.1
File Interpreter ABI Platform
abara_file_io-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 25.6 kB

Release files / abara_file_io-1.0.1.tar.gz

Download URL abara_file_io-1.0.1.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3817edf29757cd6ea96994434af907e573dda304dfb7e993109962ca2a7be152
BLAKE2b-256 checksum
How to use checksums
2a81a41c33b296c109a5dbd4f407d46e14091ac6e046268de1a10bd8c9e5926c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Release files / abara_file_io-1.0.1-py3-none-any.whl

Download URL abara_file_io-1.0.1-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba18896c39adb35b393c01404975d5041b8111f6106760c1693ce2652daca82f
BLAKE2b-256 checksum
How to use checksums
6607527d188e8d4848bfb6c71d0e9270e1d0d4f4266fa0949bf737dd9285cba5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Security for abara-file-io 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page