Quickly store arbitrary Python objects in unique files.
Project description
quickdump
Quickly store arbitrary Python objects in unique files.
- Optionally generate unique file names based on current time/date, uid, or ulid
- Optionally create and use a
~/.quickdump
hidden directory in the home folder
import random
import time
from dataclasses import dataclass
from datetime import datetime, timedelta
from quickdump import QuickDumper, QuickDumpLoader
@dataclass
class SomeObj:
a: int
b: datetime
c: bytes
if __name__ == "__main__":
with QuickDumper(
file_name="test_dump.qd",
dump_every=timedelta(seconds=2),
) as dumper:
for i in range(100):
time.sleep(0.1)
obj = SomeObj(i, datetime.now(), random.randbytes(10))
print(f"Dumping obj: {obj}")
dumper.add(obj)
for file in dumper.produced_files:
for loaded_obj in QuickDumpLoader(input_file=file).iter_objects():
print(loaded_obj)
# Prints - SomeObj(a=0, b=datetime.datetime(2022, 3, 6, 12, 52, 28, 99256), c=b';?w\xeb\xaa}\xe8\xb9tJ')
# ...
# SomeObj(a=99, b=datetime.datetime(2022, 3, 6, 12, 52, 28, 175175), c=b'%\x93\xdc\x93\x9e\x08@\xed\xe1\n')
# Saves the objects in one file in each run on the ~/.quickdump dir.
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
quickdump-0.1.0.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for quickdump-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f6f7878c4095c32e8b6da7c0713b2329a0e96a68607382fbf56b9005d80f5df |
|
MD5 | 81cab087ed9faf9a01e7b2648d1abecf |
|
BLAKE2b-256 | 0f37a0fb0031e218e6bac4d8d090f82d6cdd9d4327b6622c95f5c75c6a79e13c |