Add your description here
Project description
Table of Contents TOC
Introduction
filefox
is a simple helper toolbox for reading and writing files.
Installation
From pip
pip install filefox
From source
pip install git+https://github.com/Yevgnen/filefox.git
Usages
Reading/Writing functions
Function | Description |
---|---|
read_json |
Reading Json file |
write_json |
Writing Json file |
read_pickle |
Reading Pickle file |
write_pickle |
Writing Pickle file |
read_toml |
Reading Toml file |
write_toml |
Writing Toml file |
read_toml |
Reading text file |
write_toml |
Writing text file |
read |
Detect file extension, decompress when necessary, read file |
write |
Detect file extension, write file, compress when necessary |
These functions have the following convention of their signatures:
reader(filename, ..., file_kwargs=None, ...)
writer(obj, filename, ..., file_kwargs=None, ...)
- For all readers, the first positional argument is always the filename.
- For all writers, the first positional argument is always the dump object and the second is filename.
- All functions accpet a keyword argument
file_kwargs
which is an optionaldict
will be unpacked and passed to file opening function, e.g.open
. The other keyword arguments will be passed to internal load/dump functions.
Example
# -*- coding: utf-8 -*-
import filefox
obj = {
"name": "John",
"age": 12,
}
filefox.write_json(obj, "json_data.json")
assert obj == filefox.read_json("json_data.json")
filefox.write_json(obj, "json_data.json.gz")
assert obj == filefox.read_json("json_data.json.gz")
filefox.write(obj, "json_data.json")
assert obj == filefox.read("json_data.json")
filefox.write(obj, "json_data.json.gz")
assert obj == filefox.read("json_data.json.gz")
filefox.write_json(
obj, "json_data.json", file_kwargs={"mode": "w", "encoding": "utf8"}, indent=2
)
assert obj == filefox.read_json("json_data.json", file_kwargs={"encoding": "utf8"})
Contribution
Formatting Code
To ensure the codebase complies with a style guide, please use flake8, black and isort tools to format and check codebase for compliance with PEP8.
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
filefox-0.7.0.tar.gz
(5.1 kB
view details)
Built Distribution
File details
Details for the file filefox-0.7.0.tar.gz
.
File metadata
- Download URL: filefox-0.7.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dea49ffb100c61464a3c993cf0e5187accc94fa8647e379d9e9f0b3cbd3cb97 |
|
MD5 | 54b9dc30770b153ac9dccf3f3d32fc8e |
|
BLAKE2b-256 | 4242d31d553a700139f1184a68c33a54aba5910d85f92d393fd31e0c2cd38dae |
File details
Details for the file filefox-0.7.0-py3-none-any.whl
.
File metadata
- Download URL: filefox-0.7.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d4c83692db3e8293152df311166f4631d0b1b3a1f4c4ee04cf97ebbeb30c7eb |
|
MD5 | 9c0d74d8c3d80282cc6e5db106fa4ce8 |
|
BLAKE2b-256 | 6f5afe64348fba779db5e71e6acbd63d18b46be8262a2a87b604a017d90bed4b |