Metadata-Version: 2.2
Name: grrr
Version: 0.7.2
Summary: A set of common tools for various bear projects.
Author-Email: chaz <bright.lid5647@fastmail.com>
Requires-Python: >=3.15
Requires-Dist: fond>=0.3.19
Requires-Dist: orjson>=3.11.9
Requires-Dist: rich>=14.1.0
Description-Content-Type: text/markdown

# grrr

[![PyPI version](https://img.shields.io/pypi/v/grrr.svg)](https://pypi.org/project/grrr/)

Fast, colorful logging and a small collection of practical tools for modern Python.

`grrr` combines a [Fond](https://pypi.org/project/fond/)-backed native logger with lightweight shell-command helpers
and JSON settings. It requires CPython 3.15 or newer.

## Installation

```bash
uv pip install grrr
```

## Logging

```python
from grrr import Logger, LogLevel

with Logger("app", level=LogLevel.DEBUG, console="split") as log:
    log.debug("starting")
    log.info("ready")
    log.warning("check the configuration")
```

Console output supports color and can be routed to stdout, stderr, or split by
severity. File, buffer, and queued loggers use the same API:

```python
from grrr import Logger

with Logger.file_logger("logs/app.log") as log:
    log.info("written to a rotating file")

with Logger.buffer_logger() as log:
    log.success("captured in memory")
    record = log.records()[0]
    print(record.level, record.message, record.timestamp)

with Logger.queue_logger(console="split") as log:
    log.info("handled by the native listener")
    log.flush()
```

Child loggers share their parent's sinks while adding a qualified name:

```python
with Logger("service") as log:
    database = log.child("database")
    database.info("connected")
```

Exception tracking is opt-in and stores text snapshots rather than live frames:

```python
with Logger("worker", track_exceptions=True) as log:
    try:
        raise RuntimeError("something growled")
    except RuntimeError:
        log.exception("job failed")

    print(log.exceptions)
```

## Shell commands

Command factories preserve argument boundaries and execute without an implicit
shell by default:

```python
import sys

from grrr.cli import BaseShellCommand

command = BaseShellCommand.adhoc(sys.executable, "-c", "print('hello')")
print(command.get())
```

Synchronous and asynchronous shell sessions are available when explicit shell
interpretation or streaming output is needed.

## JSON settings

```python
from grrr.config import SimpleSettingsManager

with SimpleSettingsManager("my-app") as settings:
    settings.set("theme", "dark")
    print(settings.get("theme"))
```

Settings are stored in one JSON file, with access serialized by a file lock and
resources released through the context-managed API.

## Native hashing

Fond's deterministic hash implementations are available for any contiguous
bytes-like object without first copying it to `bytes`:

```python
from grrr.hashing import crc64_xz, murmur3_32, siphash24

checksum = crc64_xz(memoryview(payload))
bucket   = murmur3_32(payload, 42)
digest   = siphash24(payload, secret_key)  # an exact 16-byte key
```

The module also exposes CRC-32/CKSUM and FNV-1a 32/64. Algorithm names include
their precise variants so serialized hashes remain unambiguous.

## Generational registries

`SlotMap` owns values behind compact, immutable handles. Removing a value makes
its handle permanently stale, even after the native slot is reused:

```python
from grrr import SlotMap

tasks = SlotMap[str](max_size=1024)
handle = tasks.insert("compile shaders")

print(tasks[handle])
tasks.remove(handle)
assert tasks.get(handle) is None
```

Handles belong to one map incarnation and cannot resolve against another map.
Clearing or reinitializing a map invalidates all of its outstanding handles.
Iteration and `handles()`, `values()`, and `items()` operate on snapshots, so
they remain safe if the map is mutated afterward.

## Struct plugins

`PluginStruct` is an experimental composition layer over Fond's native
`Struct`. Plugins can prepare the class namespace, augment the finished class,
or wrap construction without affecting ordinary Fond structs:

```python
from grrr import PluginStruct
from grrr.structs import StructCall


class CountCalls:
    calls = 0

    def call(self, call: StructCall, /) -> object:
        self.calls += 1
        return call.proceed()


counter = CountCalls()


class Event(PluginStruct, plugins=(counter,)):
    name: str
```

Plugins inherit in declaration order. Reusing the same plugin object through a
diamond runs it once; a plugin can define `__struct_plugin_key__` when locally
declared replacements should resolve independently created feature bases.

The included `SingletonStruct` convenience base caches one successfully built
instance per concrete class:

```python
from grrr import SingletonStruct


class Settings(SingletonStruct):
    profile: str


settings = Settings("production")
assert Settings("ignored") is settings
Settings.reset_instance()
```

Plugin-enabled reified Structs are deliberately rejected until Fond provides a
native planning hook for them.

## Version

```bash
python -c "import grrr; print(grrr.__version__)"
```
