Metadata-Version: 2.4
Name: bytewise
Version: 0.1.0
Summary: Standalone neural MIME detection from raw bytes
Author-email: Chris Mattmann <chris.mattmann@gmail.com>
License-Expression: Apache-2.0
Keywords: mime,file-type,neural-network,transformer,byte-analysis
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Database :: Front-Ends
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: <3.13,>=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: numpy>=1.26
Provides-Extra: inference
Requires-Dist: tensorflow<2.19,>=2.18; extra == "inference"
Provides-Extra: metal
Requires-Dist: tensorflow<2.19,>=2.18; extra == "metal"
Requires-Dist: tensorflow-metal<1.3,>=1.2; extra == "metal"
Provides-Extra: research
Requires-Dist: beautifulsoup4>=4.13.3; extra == "research"
Requires-Dist: cbor2>=5.6; extra == "research"
Requires-Dist: requests; extra == "research"
Dynamic: license-file

# Bytewise MIME detector

[![CI](https://github.com/chrismattmann/bytewise/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/chrismattmann/bytewise/actions/workflows/ci.yml)
[![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE.txt)
[![PyPI version](https://img.shields.io/pypi/v/bytewise.svg)](https://pypi.org/project/bytewise/)

> **Working name:** `bytewise` may change before the first public Git release.

Bytewise is a standalone neural MIME detector trained on raw file bytes. It
does not require Java, a Tika server, a filename, or a file extension. The
repository preserves its complete research lineage: BFA/BFC baselines, neural
experiments, strict-host validation, deduplication audits, and D3 reports.

The frozen v1 release candidate is a compact Transformer trained on the first
4,096 bytes of 863,871 TREC-DD POLAR payloads. It predicts 57 MIME classes.

## Usage

Homebrew Python is an externally managed environment and must not be modified
with `pip --break-system-packages`. For the command-line application, install
Bytewise into an isolated Python 3.12 environment with `uv`:

```bash
uv tool install --python 3.12 --editable "$HOME/git/bytewise[metal]"
uv tool update-shell
```

Open a new terminal (or add `$HOME/.local/bin` to `PATH`) and verify it:

```bash
bytewise --version
bytewise model-info
```

The `metal` extra pins the validated TensorFlow 2.18.1 and
`tensorflow-metal` 1.2 runtime. On a non-Mac system, replace `metal` with
`inference`.

For development or library use, keep the dependency in a project environment:

```bash
cd "$HOME/git/bytewise"
uv sync --python 3.12 --extra metal --group tests
uv run bytewise model-info
uv run python
```

Inside that `uv run python` session:

```python
from bytewise import Detector

detector = Detector.load_default()
result = detector.detect_file("document.bin")

print(result.mime_type)
print(result.confidence)
print(result.alternatives)
```

The same model is available from the command line:

```bash
bytewise detect document.bin image.dat
bytewise detect document.bin --top-k 5 --threshold 0.80 --json
cat unknown.bin | bytewise detect -
bytewise supported
bytewise model-info
```

Allow uncertain inputs to abstain so another detector can handle them:

```python
detector = Detector.load_default(confidence_threshold=0.80)
result = detector.detect_bytes(payload)
if result.abstained:
    # Fall back to tika-python, libmagic, or another detector.
    pass
```

## Frozen v1 model

The selected model is `polar-byte-transformer-seed550-v1`:

- Validation accuracy: 96.77%
- Independent-reference accuracy: 94.59%
- Input: first 4,096 raw bytes
- Labels: 57 MIME types
- Model SHA-256:
  `72a2f5f2dd0fbb4ffaf88488618bc8e034c03876c7cea94d11da23439ed5b849`

See the [model card](artifacts/polar-byte-transformer-seed550-v1/MODEL_CARD.md)
and [Full-v3 report](reports/full-v3/index.html) for the complete evidence.

## Repository organization

- `src/bytewise/`: production API and migrated byte-frequency research code
- `artifacts/`: immutable model release bundle
- `configs/`, `scripts/`: reproducible experiments and evaluation
- `reports/`: curated D3 reports from early pilots through Full-v3
- `docs/`: research and repository-extraction documentation
- `tests/`: standalone production and research regression tests

Dataset bytes, feature caches, databases, raw predictions, and transient logs
are intentionally kept outside Git.
