Metadata-Version: 2.5
Name: phasmid-profile-gen
Version: 0.1.0
Summary: Generate Phasmid browser profiles from BrowserForge marginals and captured real devices
Project-URL: Homepage, https://github.com/tintty1/phasmid-profile-gen
Project-URL: Repository, https://github.com/tintty1/phasmid-profile-gen
Project-URL: Issues, https://github.com/tintty1/phasmid-profile-gen/issues
License-Expression: BSD-3-Clause
License-File: LICENSE
License-File: src/phasmid_profile_gen/data/LICENSES.md
Keywords: browser fingerprint,browser profile,chromium,phasmid
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: Topic :: Internet :: WWW/HTTP :: Browsers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.12
Requires-Dist: jsonschema>=4.23
Provides-Extra: location
Requires-Dist: maxminddb==3.2.0; extra == 'location'
Requires-Dist: timezonefinder-data==4.2026.5; extra == 'location'
Requires-Dist: timezonefinder==9.2.0; extra == 'location'
Description-Content-Type: text/markdown

# phasmid-profile-gen

[![Test](https://github.com/tintty1/phasmid-profile-gen/actions/workflows/test.yml/badge.svg)](https://github.com/tintty1/phasmid-profile-gen/actions/workflows/test.yml)
[![License: BSD-3-Clause](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](LICENSE)
[![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)

Generates device profiles for [Phasmid](https://github.com/tintty1/phasmid), the
Chromium fork that reports the device described by one JSON profile instead of
the machine it runs on.

This is Phasmid's `tools/genprofile` as a standalone package. The data it needs
is bundled in compressed form (about 60 KB), so it runs without a Phasmid
checkout and without BrowserForge installed. From the same captures it produces
the same profiles as `tools/genprofile`, byte for byte, except for the
generator's name in `captured.note`.

## Install

```bash
pip install phasmid-profile-gen                # profiles with a given time zone
pip install 'phasmid-profile-gen[location]'    # also place profiles at a proxy exit IP
```

Python 3.12 or newer. The `location` extra adds `timezonefinder` (with its
boundary data, about 33 MB) and `maxminddb`, pinned exactly because they decide
which zone and position a seed gets.

## Use

```python
from phasmid_profile_gen import dumps, generate_profile

# Placed where the proxy comes out: zone, geolocation, WebRTC address, languages.
profile = generate_profile("windows", exit_ip=proxy_exit_ip)

# Or with an explicit locale, reproducibly.
profile = generate_profile(
    "linux",
    seed="0a1b2c3d4e5f60718293a4b5c6d7e8f9",
    timezone="Europe/Berlin",
    languages=["de-DE", "de", "en-US", "en"],
)
open("profile.json", "w").write(dumps(profile))
```

```bash
phasmid-profile-gen generate --os windows --exit-ip <proxy exit IP> -o profile.json
phasmid-profile-gen generate --os linux --seed 0a1b2c3d4e5f60718293a4b5c6d7e8f9 \
    --timezone Europe/Berlin --languages de-DE,de,en-US,en -o profile.json
phasmid-profile-gen gpus          # GPUs the bundled captures back (for --gpu)
phasmid-profile-gen captures      # the bundled captures
phasmid-profile-gen locate <proxy exit IP> --seed <seed>
phasmid-profile-gen validate profile.json
```

Give exactly one of an exit IP and a time zone. **Generate Windows profiles
with an exit IP.** Windows Chrome answers geolocation from the system location
provider, so a Windows profile with no position is a stronger tell than a Linux
one. The seed is 32 lowercase hex characters. When omitted, a new one is drawn;
read it back from `profile["seed"]`. The same seed and inputs always give the
same bytes (`dumps`).

Other functions: `locate(ip, seed)`, `list_gpus()`, `list_captures()`,
`validate(profile)` (against the bundled Phasmid schema) and `new_seed()`.
Errors are `GenerationError`, `LocationError` and `geoip.GeoipError`.

## What a profile is made of

| Part | From |
| --- | --- |
| OS identity, CPU threads, memory class, touch points, screen and window geometry, media device presence, battery | A [BrowserForge](https://github.com/daijro/browserforge) sample for desktop Chrome on the OS, drawn from the seed. Each node is drawn for one sampled user agent, filtered to what the OS and the capture allow. |
| GPU, WebGL and WebGPU surface, fonts, voices, audio, codecs, system colours, pointer, preferences, RAM, disk, media device labels | One capture of a real device. On Linux the GPU's identity may instead be one that the capture's driver class reports with the exact same WebGL surface (Phasmid decision `gpu-claims-stay-within-a-captured-host-class`). |
| Time zone, geolocation, WebRTC public IP, languages | The exit IP: DB-IP City Lite, timezonefinder, CLDR, and Chrome's default accept-languages for the country's UI locale. Otherwise the time zone and languages you pass. |

No user-agent or version string is written. Phasmid builds those from its own
version. Nothing is invented: a field only a capture can supply is never
filled in by guessing, and an OS without a capture fails with
`MissingCaptures`. `captured.note` records where every part came from.

### Bundled captures

Run `phasmid-profile-gen captures` for the current list. It is also in
[`data/manifest.json`](src/phasmid_profile_gen/data/manifest.json), which lists
the dumps refused and why.

- Phasmid's own: Linux (Arch, RTX 3060) and Windows 11 (Intel UHD 600).
- From the [collector app](https://phasmid.ecomeezy.com/): Windows 10 (Intel
  HD Graphics 4600). Visitors grant no media permission, so the dump has no
  device labels. Profiles built from it claim no microphone, speaker or
  camera.

A Windows capture backs only its own version: a Windows 11 capture gives
Windows 11 profiles (`platformVersion` 13 and up), a Windows 10 capture
Windows 10 ones. Their fonts differ (Windows 11 dropped HoloLens MDL2 Assets
and added Segoe Fluent Icons). This is the one intended difference from
`tools/genprofile`, which drew either version for its Windows 11 capture.

## The location database

The exit IP is looked up in DB-IP IP to City Lite (CC BY 4.0, "IP Geolocation
by DB-IP"). It is about 127 MB, so it is not bundled. The build pinned in
`data/dbip-city-lite.json` is downloaded on first use, checked against the
pin, and kept in `$XDG_CACHE_HOME/phasmid/geoip/`. That is the cache Phasmid's
tools use, so an existing download is reused.

```bash
phasmid-profile-gen geoip                     # download and verify now
phasmid-profile-gen geoip --archive dbip-city-lite-2026-10.mmdb.gz
```

DB-IP serves only the last two monthly builds. Once the pinned one is gone,
either install a saved copy with `--archive`, or use any other DB-IP City Lite
build with `PHASMID_GEOIP_MMDB=/path/to/dbip-city-lite.mmdb`, `--geoip-db` or
`geoip_db=`. Another build is not checked against the pin; the profile's note
names its build date and sha256 instead.

## Rebuilding the data

`src/phasmid_profile_gen/data/` is generated, compressed and committed. It is
rebuilt from a Phasmid checkout and collector-app dumps by
[`scripts/build_data.py`](scripts/build_data.py):

```bash
uv sync --group build-data
# in collector-app: npm run pull -- --out captures
uv run --group build-data python scripts/build_data.py \
    --phasmid ../phasmid \
    --collector ../collector-app/captures/d1-2026-11-05/dumps
```

The build:

- maps every dump with the checkout's own `tests/consistency/capture.py` (the
  code `consistency capture` runs), and checks Phasmid's captures against their
  records as `tools/genprofile` does;
- keeps a collector dump only if it is stock desktop Google Chrome on Windows
  or Linux, with a hardware GPU, a consistent UA and UA-CH, and a window inside
  its screen, and only if it maps to a valid profile. Each refusal is listed
  with its reason in `manifest.json`;
- stores only what generation reads. Raw dumps and visitors' locales are never
  written;
- restricts BrowserForge's network to desktop Chrome on Windows and Linux and
  the nodes the generator draws. `tests/test_data.py` checks every table
  against browserforge itself.

The output is deterministic, so a rebuild from the same sources gives the same
bytes. A Linux collector dump also needs the operator's OS version (`?manual=1`),
which a page cannot read.

## Develop

```bash
uv sync --all-extras --group build-data
uv run pytest
uv run pre-commit run --all-files
PHASMID_GEOIP_NETWORK=1 uv run pytest -m network   # reads the real DB-IP build
```

Releases are published to PyPI by `.github/workflows/publish-pypi.yaml` when a
GitHub release is published. The version comes from the release tag
(`uv-dynamic-versioning`, e.g. `v0.1.0`). Publishing uses PyPI trusted
publishing: register the repository and that workflow as a trusted publisher
of `phasmid-profile-gen` on PyPI once.

## Licence

The code is BSD 3-Clause, as Phasmid is ([`LICENSE`](LICENSE)). The bundled
data keeps its sources' licences:

- BrowserForge's network: Apache 2.0.
- Unicode CLDR: Unicode License v3.
- Chromium's locale table: BSD-style.

DB-IP (CC BY 4.0) and timezone-boundary-builder (ODbL 1.0) are used at runtime
but not bundled. See
[`data/LICENSES.md`](src/phasmid_profile_gen/data/LICENSES.md).
