Skip to main content

Files for Fun; Python Utilities

Project description

FilesFF - Files For Fun

PyPI version PyPI downloads GitHub PyPI - Python Version

  • 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 hashes)

Uploaded Source

Built Distribution

filesff-0.0.7-py3-none-any.whl (9.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page