Files for Fun; Python Utilities
Project description
FilesFF - Files For Fun
- python package to work with file handles
- use handles of files as parameters without keeping open files
- replace file handles easily with mocks
- handle many file types with generic protocol
to install with all extras
pip install filesff[protobug,ujson,cap,msgpack,s3]
Usage
read a json from gzip compressed file:
accessor = GzippedFileHandle.of_str("./file.gz").access(JsonFormatter())
accessor.dump({"json": "data"})
write a protobuf into a temp file
pip install fileff[protobuf]
from google.protobuf.timestamp_pb2 import Timestamp
accessor = PathFileHandle.of_temp().access(ProtoBytesFileFormatter)
now = Timestamp()
now.FromDatetime(datetime.now())
accessor.dump(now)
loaded_now = accessor.load(message_cls=Timestamp)
implement new file format:
class NewFileFormatter(FullTextFileFormatter):
def load(self, reader: IO, **_) -> AnyStr:
return reader.read().replace("a", "e")
def dump(self, writer: IO, value: Any, **_):
writer.write(value.replace("e", "a"))
use it
file_accessor = PathFileHandle.of_str("./path.ae").access(NewFileFormatter())
file_accessor.dump("ababab")
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
filesff-0.0.7.tar.gz
(6.3 kB
view details)
Built Distribution
File details
Details for the file filesff-0.0.7.tar.gz
.
File metadata
- Download URL: filesff-0.0.7.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.11.1 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a10b565001f8b19068be882278b8408e9f4bf7b21064f5ca02b21c12186a7353 |
|
MD5 | 86760802aadcbac251058dfcdbff996b |
|
BLAKE2b-256 | e192090747e05527f2111b132727a0a751b3e885f4b43bc0f2c08402d8c89dd9 |
File details
Details for the file filesff-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: filesff-0.0.7-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.11.1 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 357441809bea2bb0e9088028f72871723a46090efde55fa72c44631d0f265189 |
|
MD5 | 402a1910155e435a3551fe3057c0a86e |
|
BLAKE2b-256 | 53002e48f1ce44c1bf21ca7c1a72a8e2b5716ca3b3b03cea12a01f4cb92ec5bf |