pychromy
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_sizeandeqcv_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.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pychromy-0.1.1.tar.gz | 61.9 kB | With provenance | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pychromy-0.1.1-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details |
| pychromy-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| pychromy-0.1.1-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 749.7 kB
Release files / pychromy-0.1.1.tar.gz
| Download URL | pychromy-0.1.1.tar.gz |
|---|---|
| Size | 61.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d91f3cb97811373298f4a04fabcc67dfa5dea6c8de3358e5e75464102c84c1f
|
|
BLAKE2b-256 checksum How to use checksums |
221eb5c11f62b726b320f499ddef13f1e69a3a4335fa6fa9c1f284a7674b934d
|
| 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 logRelease files / pychromy-0.1.1-cp39-abi3-win_amd64.whl
| Download URL | pychromy-0.1.1-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 181.7 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
7452e0d2b4546142842edf8a73285be2590a90257d8feee598876ce027c51277
|
|
BLAKE2b-256 checksum How to use checksums |
78805445e1a4ed0c4ed771e894715eb07a5b5efa108983bf3fdfedefc915178b
|
| 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 logRelease files / pychromy-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pychromy-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 261.8 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0534ad73269350daf39fd1921be06246daa6c5048999fdfb981867db077b24e1
|
|
BLAKE2b-256 checksum How to use checksums |
21f375377bf9674e1dc9ff69bda2d1e0e1359155774ab77554783af1e228f9c0
|
| 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 logRelease files / pychromy-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | pychromy-0.1.1-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 244.4 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b48cc322b2c71d1e00d240dc45f0000cebb6444e86ce230d4a75d15360843b20
|
|
BLAKE2b-256 checksum How to use checksums |
8e397deccffbef83e2c15638a2166f67b1ef9d591d238252054e7c535ca2b36e
|
| 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 logSecurity for pychromy 0.1.1
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.
Attestation for pychromy-0.1.1.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 logA 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.