Skip to main content

filedgr-pkg-utils

Build Status Coverage Python Version PyPI version License

A comprehensive, production-ready Python utility toolkit for modern distributed systems, Web3 integrations, and data-heavy microservices.

filedgr-pkg-utils provides a unified, protocol-driven API for cryptography, resilient networking, deterministic data serialization, compression, and structured logging.

📦 Installation

Install the base package (extremely lightweight, ideal for AWS Lambda):

pip install filedgr-pkg-utils

Install with optional image perceptual hashing support (includes Pillow and ImageHash):

pip install "filedgr-pkg-utils[images]"

🚀 Prominent Features & Examples

1. Resilience & Aspect-Oriented Hooks

Stop writing try/except blocks with time.sleep(). Stack our context-aware decorators to build bulletproof network calls and clean up your business logic.

from filedgr_pkg_utils.resilience.decorators import retry, circuit_breaker, fallback
from filedgr_pkg_utils.hooks.post_action import post_action

def audit_log(result, *args, **kwargs):
    print(f"Audit: Successfully fetched data {result}")

def serve_stale_data(*args, **kwargs):
    return {"status": "stale", "data": []}

@post_action(callback=audit_log)
@fallback(fallback_function=serve_stale_data)
@circuit_breaker(failure_threshold=5, recovery_timeout_seconds=30)
@retry(max_attempts=3, backoff_multiplier=2.0)
async def fetch_web3_data(node_url: str):
    # This function is completely protected.
    # It will retry on failure, trip a circuit breaker if the node is down,
    # serve stale data if all else fails, and log the result when successful.
    pass

2. Unified Compression

A single, clean protocol for zip, gzip, zstd, and brotli. Easily swap algorithms without changing your application code.

from filedgr_pkg_utils.compression import CompressionUtils, ZstdAlgorithm, ZipAlgorithm

# Swap from standard Zip to high-performance Zstd in one line
utils = CompressionUtils(ZstdAlgorithm(level=3))

# Compress bytes
compressed_data = utils.compress(b"Hello World")

# Compress files and directories
utils.compress_file("data.json", "data.json.zst")

3. Canonical Serialization & Cryptography

Generate deterministic, whitespace-free, and alphabetically sorted JSON payloads—perfect for creating verifiable hashes and blockchain signatures.

from filedgr_pkg_utils.canonicalization.canonical_json_mixin import CanonicalJsonMixin
from datetime import datetime, timezone

class BlockchainPayload(CanonicalJsonMixin):
    z_field: str
    a_field: int
    timestamp: datetime

payload = BlockchainPayload(
    z_field="last",
    a_field=1,
    timestamp=datetime(2023, 10, 25, 12, 30, 0, tzinfo=timezone.utc)
)

# Output is strictly deterministic: {"a_field":1,"timestamp":"2023-10-25T12:30:00.000Z","z_field":"last"}
json_string = payload.canonical_json()

4. Zero-Config Structured JSON Logging

Output logs as deterministic JSON for flawless Datadog or AWS CloudWatch ingestion. Fully integrates with Python's standard logging library.

from filedgr_pkg_utils.logging import LoggerFactory

# Automatically reads FILEDGR_LOGGING_ENABLED env var
logger = LoggerFactory.get_logger(__name__)

logger.info("Processing file", extra={"file_id": "ABC-123", "correlation_id": "999"})
# Output: {"timestamp": "2026-05-14T12:00:00.000Z", "level": "INFO", "logger": "__main__", "message": "Processing file", "file_id": "ABC-123", "correlation_id": "999"}

5. Perceptual Image Hashing (Optional)

Detect visually similar images, compression artifacts, and resized duplicates using Hamming distance.

from filedgr_pkg_utils.images.hashing import PHashAlgorithm, ImageHashUtils

utils = ImageHashUtils(PHashAlgorithm())

hash_orig = utils.hash_image("original.png")
hash_comp = utils.hash_image("compressed_artifact.jpg")

if utils.is_similar(hash_orig, hash_comp, max_distance=5):
    print("These images are visually similar!")

🛠️ Development & Testing

This project enforces high coverage and clean coding standards.

To run the test suite with coverage:

make test-coverage

To run the linter:

make lint

Metadata

Release files for filedgr-pkg-utils 0.8.4

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

Source distribution (sdist)

Source distribution for filedgr-pkg-utils 0.8.4
File Size Uploaded Provenance Actions
filedgr_pkg_utils-0.8.4.tar.gz 23.3 kB Without provenance Details for filedgr_pkg_utils-0.8.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for filedgr-pkg-utils 0.8.4
File Interpreter ABI Platform Actions
filedgr_pkg_utils-0.8.4-py3-none-any.whl Python 3 none any Details for filedgr_pkg_utils-0.8.4-py3-none-any.whl

Total release size: 57.2 kB

Release files / filedgr_pkg_utils-0.8.4.tar.gz

Download URL filedgr_pkg_utils-0.8.4.tar.gz
Size 23.3 kB
Tags Source
SHA-256 checksum
How to use checksums
67febfa29f6caa788ae9809e2e11828a13ab6acdf0099e92b5ff7181d4de7536
BLAKE2b-256 checksum
How to use checksums
963ad776529f2e811d2a4d0273586bf7d23394eed114101a6c340e86f0d66dbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / filedgr_pkg_utils-0.8.4-py3-none-any.whl

Download URL filedgr_pkg_utils-0.8.4-py3-none-any.whl
Size 33.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ec0074587e5a3ad9f5bed8bf2de337d0ebd1d3b16c96204f205fa0afca1a2bb
BLAKE2b-256 checksum
How to use checksums
035d6e0beb5e14494eaecd84908d73350c6c53f3602bf8acdb5132fb9867c938
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for filedgr-pkg-utils 0.8.4

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

0.8.4 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