Skip to main content

pychromy

PyPI license: GPL-3.0-or-later DOI

Chromy's method of sequential random sampling with probability minimum replacement, from Python. The procedure selects units one at a time down an ordered list, each with probability proportional to its size, so that every unit's realised number of selections differs from its expected number by less than one — and the sample size is always exact. It is how many large establishment and household surveys draw their samples, and how PROC SURVEYSELECT METHOD=PPS_SEQ works; until now it lived only inside proprietary software and one Stata module.

The engine is the dependency-free Rust crate chromy-core, shared with the R package chromy. This module needs nothing besides Python: matrices are lists of columns, so a pandas user writes [df[c].tolist() for c in cols] and a plain-list user writes the lists directly.

Install

pip install pychromy

A design in a few lines

import pychromy

# A frame of 300 schools: a region, a size, an outcome to estimate.
import random
rng = random.Random(2026)
region = [rng.choice(["north", "east", "south", "west"]) for _ in range(300)]
pupils = [round(rng.lognormvariate(4.5, 0.9)) for _ in range(300)]
outcome = [rng.lognormvariate(5.0, 0.7) for _ in range(300)]

# Expected hits from the size; serpentine order within region by size;
# the selection, reproducible from its seed.
s = pychromy.sample(
    size=pupils, n=40,
    keys=[region, [float(p) for p in pupils]],
    seed=20261022,
)
sum(s["hits"])          # 40, always: the sample size is exact

# The estimator that matches the design, with its standard error.
y = [[outcome[u] for u in s["unit"]]]
est = pychromy.estimate_total(
    y, s["position"], s["expected_hits"], s["hits"]
)
est["total"], est["se"]

What it does

  • sample — a whole design in one call: size to expected hits, keys to serpentine order, head, selection, weights.
  • pmr — the sequential selection itself, deterministic given the uniforms, with an explicit account of every floating-point adjustment.
  • serpentine_order — hierarchical serpentine (or nested) sorting: implicit stratification without seams; string keys rank by byte order, never by locale.
  • mpps_size and eqcv_allocation — a maximal size measure over several auxiliary variables, and the allocation that equalises their anticipated coefficients of variation.
  • expected_hits — sizes into expected hits, certainties resolved by iteration, or units allowed several hits under minimum replacement.
  • select — the full procedure with every draw under your control, for callers that bring their own generator.
  • estimate_total — the multiplicity estimator with the successive-difference variance.

Randomness, stated plainly

The engine takes its randomness as arguments. sample(seed=...) draws from a fixed, documented generator (SplitMix64), so a published design can name its seed and be replayed. R and Python reproduce themselves, not each other: each language consumes its own generator, but both run the same engine, pinned bit for bit to the same reference implementation by the golden tests in chromy-core.

References

  • Chromy, J. R. (1979). Sequential sample selection methods. Proceedings of the American Statistical Association, Survey Research Methods Section, 401–406.
  • Chauvet, G. and Le Gleut, R. (2021). Properties of Chromy's sampling procedure. Survey Methodology, 47(2), 321–347.
  • Folsom, R. E., Potter, F. J. and Williams, S. R. (1987). Notes on a composite size measure for self-weighting samples in multiple domains. Proceedings of the ASA, Section on Survey Research Methods, 792–796.

License

GPL-3.0-or-later. A project of the CAST Lab, UFPE.

Metadata

Release files for pychromy 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pychromy 0.2.0
File Size Uploaded Provenance
pychromy-0.2.0.tar.gz 62.4 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for pychromy 0.2.0
File Interpreter ABI Platform
pychromy-0.2.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
pychromy-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
pychromy-0.2.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details

Total release size: 769.8 kB

Release files / pychromy-0.2.0.tar.gz

Download URL pychromy-0.2.0.tar.gz
Size 62.4 kB
Tags Source
SHA-256 checksum
How to use checksums
878379fa9078b578785fb1f18f9240d9ce2683939ae3146cb0cafe92126adca3
BLAKE2b-256 checksum
How to use checksums
e94d9b57219e44c949c19713744c09feed80bedfd1779b5a33d7ec190b7ffa66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Release files / pychromy-0.2.0-cp39-abi3-win_amd64.whl

Download URL pychromy-0.2.0-cp39-abi3-win_amd64.whl
Size 188.3 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c07da813bc827918393242cb045c1b7d81ada44ccdd38f93922a7604ca41e2cf
BLAKE2b-256 checksum
How to use checksums
a9f8572b4c2dad3134c0641bd277676c0adec68d39f05ee0b6efdc21dead28d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Release files / pychromy-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pychromy-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 268.5 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
1530b78dfc19d8561802cd77ba9e66dab04a9ad0fa005656eb80c17934fe3825
BLAKE2b-256 checksum
How to use checksums
9dcf537dfc690e816e900ff7370a7a76d117473f70c6f66687b95d8c56f4ac47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Release files / pychromy-0.2.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL pychromy-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Size 250.7 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ffb2495f9ac7c32b2fe302425bfdc0cad20118a095eb1290d63db5a044eb0278
BLAKE2b-256 checksum
How to use checksums
7f9b294d89538d968a47d42f4e5f3ed65676c1fb19996529097180a8d74d8bc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Security for pychromy 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for pychromy-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page