Metadata-Version: 2.5
Name: hashy
Version: 0.15.2
Summary: simple hash library for string, file, dict, set and list
Project-URL: Homepage, https://github.com/jamesabel/hashy
Project-URL: Repository, https://github.com/jamesabel/hashy
Author-email: abel <j@abel.co>
License-Expression: MIT
License-File: LICENSE
Keywords: hash
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Programming Language :: Python :: Free Threading :: 2 - Beta
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: msqlite>=1.0.1
Requires-Dist: platformdirs
Description-Content-Type: text/markdown

# hashy

[![CI](https://github.com/jamesabel/hashy/actions/workflows/python-package.yml/badge.svg)](https://github.com/jamesabel/hashy/actions/workflows/python-package.yml)
[![codecov](https://codecov.io/gh/jamesabel/hashy/branch/master/graph/badge.svg)](https://codecov.io/gh/jamesabel/hashy)
[![PyPI version](https://img.shields.io/pypi/v/hashy.svg)](https://pypi.org/project/hashy/)
[![Python versions](https://img.shields.io/pypi/pyversions/hashy?cacheSeconds=3600)](https://pypi.org/project/hashy/)
[![Downloads](https://img.shields.io/pypi/dm/hashy.svg)](https://pypi.org/project/hashy/)
[![License: MIT](https://img.shields.io/pypi/l/hashy.svg)](https://github.com/jamesabel/hashy/blob/master/LICENSE)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

Another hash library, but with a twist. It provides a simple interface to generate hashes for strings, files, dicts, 
lists and sets. It also provides a decorator to cache the results of a function to disk and (optionally) memory.

## Installation

```
pip install hashy
```

## Introduction

hashy provides an md5, sha256, sha512 or crc64nvme for string, file, dict, list and set.

String and file hashes are conventional and can be compared to other implementations. For example,
you can go to an online hash calculator for "a" and get the same hash as hashy generates.

crc64nvme is the CRC-64/NVME checksum (as used by the NVMe specification and AWS S3 object
integrity checking), returned as a 16-character hex string.

Hashes for complex data types like dict, list and set are specific to hashy.

`cachy` supports multithreading and multiprocessing via the [`msqlite`](https://pypi.org/project/msqlite/) library,
which retries SQLite's `database is locked` errors with jittered backoff. A store that still cannot be written after
30 seconds (`hashy.cache.LOCK_TIMEOUT_S`) is logged as a warning and counted in `get_counters().cache_store_failed_counter`;
the caller always receives the computed result.

Requires Python 3.12 or later. Free-threaded Python is supported and tested (3.14t and 3.15t): hashy and its dependencies
run with the GIL off, and `cachy` and its counters are safe to use from threads running in parallel.

## cachy

`hashy` also provides `cachy`, a decorator that can be used to persistently cache the results of a function to 
disk and (optionally) memory. It is similar to `@functools.cache`, except:

- Persistent (saved to local disk in a sqlite database)
  - Optionally can be saved to a user-specified directory, otherwise it's the usual cache directory for the OS
- Optional user-specified cache life.
- Doesn't require arguments be frozen and/or pickle-able. Uses hashy to create a hash of the arguments.


# Example

```

from hashy import get_string_sha256, cachy

print(get_string_sha256("a"))  # prints ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb

@cachy()
def func(a):
    return a + a

print(func(2))  # prints 4

```
