Skip to main content

pychromy

PyPI license: GPL-3.0-or-later

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.1.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.1.0
File Size Uploaded Provenance
pychromy-0.1.0.tar.gz 61.4 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for pychromy 0.1.0
File Interpreter ABI Platform
pychromy-0.1.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
pychromy-0.1.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.1.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details

Total release size: 748.3 kB

Release files / pychromy-0.1.0.tar.gz

Download URL pychromy-0.1.0.tar.gz
Size 61.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4cd9a21e2e2c583096cad50448bc72c45b7e326fbacfeb07b3c0cc06d695e216
BLAKE2b-256 checksum
How to use checksums
c32b2dadc827aacb58332d4c936aff0a8ae2d51c7a8ee3847e0704a7eacab451
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.1.0-cp39-abi3-win_amd64.whl

Download URL pychromy-0.1.0-cp39-abi3-win_amd64.whl
Size 181.4 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
9780de888073a2a3595761e389dbbe78425e7d6ad3fd09ab994dc9516a172135
BLAKE2b-256 checksum
How to use checksums
308eca1796f0cfce44b5afb8f3e6df1760bca15436dbd14f1781f3997dacaa5f
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.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pychromy-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 261.3 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
478973a7b47ea56efdaf1592327d27a17b8e91b126f79b2ec4fffeb0206858c2
BLAKE2b-256 checksum
How to use checksums
dbdfe6577c15c51c8ee4f8025a3e66f3e8daa75dd7cae08352034d0fabbac37c
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.1.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL pychromy-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Size 244.2 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2e5b822c21d4a6b30afeace2abe34a7dd65b6bca2c5f21fad4ff3096a03f27c6
BLAKE2b-256 checksum
How to use checksums
2c15b1da79086069b7bcca9dfdb444441fd17557e460eb86efc97d0f12c77e32
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.1.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.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

4 release files Full provenance

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