semvec/pypi-packages huggingface dataset:
tuplehash 0.1.0a2
Pure Python reimplementation of CPython's `tuplehash` function with exact overflow behavior, designed for hashing user-defined immutable sequences.
Requires Python: >=2

# tuplehash

Pure Python reimplementation of CPython's `tuplehash` function with exact overflow behavior, designed for hashing user-defined immutable sequences.

## The Current Pain Point

Currently in Python, if you want your custom immutable sequence to hash like a tuple:

```python
from typing import TypeVar, Sequence

T = TypeVar('T', covariant=True)


class MySequence(Sequence[T]):
    def __hash__(self):
        return hash(tuple(self))
```

This creates memory overhead for large collections.

Until such stdlib functionality exists, `tuplehash` provides:

```python
# Explicitly provide a non-negative int to `len` if `len(iterable)` doesn't work
def tuplehash(iterable, length=None): ...
```

So you can do this:

```python
from typing import TypeVar, Sequence

from tuplehash import tuplehash

T = TypeVar('T', covariant=True)


class MySequence(Sequence[T]):
    def __hash__(self):
        return tuplehash(self)
```

This gives you stdlib-quality hashing today.

## Features

- **Strict overflow behavior** using [custom fixed-width integer types](https://github.com/jifengwu2k/fixed-width-int)
- **Version-specific implementations** matching:
    - Python 2.7/3.0-3.7: Original multiplicative hash
    - Python 3.8+: Simplified [xxHash algorithm](https://github.com/Cyan4973/xxHash/blob/master/doc/xxhash_spec.md)

## Installation

```bash
pip install tuplehash
```

## Usage

```python
from tuplehash import tuplehash

# Basic usage
assert tuplehash((1, 2, 3)) == hash((1, 2, 3))

# Works with any collection
from collections import namedtuple

Point = namedtuple('Point', ['x', 'y'])
assert tuplehash(Point(3, 4)) == hash(Point(3, 4))
```

## Implementation Details

### Version-Specific Algorithms

| Python Version | Algorithm           | Key Characteristics                                                     |
|----------------|---------------------|-------------------------------------------------------------------------|
| <3.8           | Multiplicative hash | Initial value `0x345678`, multiplier `1000003`, length-dependent addend |
| ≥3.8           | Simplified xxHash   | Single accumulator, 31/13-bit rotations, prime multiplications          |

### Overflow Handling

Uses [custom `Signed`/`Unsigned` types]((https://github.com/jifengwu2k/fixed-width-int)) to exactly replicate:

- 32-bit overflow on 32-bit platforms
- 64-bit overflow on 64-bit platforms
- All intermediate casting behaviors

## Limitations

- Performance overhead vs native implementation

## Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

## License

This project is licensed under the [MIT License](LICENSE).
python-squarelet 0.2.1
Python library that handles token authentication for MuckRock and DocumentCloud
Requires Python: <=3.12,>=3.8

# python-squarelet
A Python wrapper for Squarelet, allowing for authentication with MuckRock systems like MuckRock Requests and DocumentCloud.

## Features
- Token-based Authentication: Easily authenticate with MuckRock services using username/password or refresh tokens.
- Rate Limiting: Automatically applies rate limiting to prevent exceeding API request limits.
- Automatic Token Refresh: Seamlessly refresh your access tokens when expired without manual intervention.
- Retry Logic: Built-in automatic retries for failed requests, ensuring robust interaction with MuckRock services.
- API Request Handling: Send GET, POST, PUT, DELETE, and other HTTP requests to MuckRock’s API with an easy-to-use interface.
- Customizable Request Headers: Extend or modify request parameters (like headers) through flexible client configuration.
- Error Handling: Provides detailed error handling with custom exceptions for API errors, credentials issues, and missing resources.

## Installation

```bash
$ pip install python-squarelet
```

## Usage
```python
# If you intend on accessing MuckRock requests, the base_uri would be https://www.muckrock.com/api_v1/ or https://www.muckrock.com/api_v2/
base_uri="https://api.www.documentcloud.org/api/"
from squarelet import SquareletClient
# Authenticating with Squarelet using your credentials
client = SquareletClient(base_uri=base_uri, username="your_username", password="your_password")
# Example API call that gets data about your DocumentCloud account.
my_user = client.request("get", "users/me/")
# Print the response data about your DocumentCloud account. 
print(my_user.text) 
```

Generally, it is safer to access your username as local environment variables using [os.environ](https://docs.python.org/3/library/os.html#os.environ) instead of specifying your username and password as strings, especially if publishing this code anywhere. After setting your local environment variables SQ_USERNAME and SQ_PASSWORD with your credentials, you can access them like so. 
```python
username = os.environ["SQ_USERNAME"]
password = os.environ["SQ_PASSWORD"]
```