Skip to main content

A fast and efficient percentile calculator written in Rust.

Project description

percently

Fast percentile calculator written in Rust — shipped as a Python package.

CI PyPI Python versions License Rust maturin

Motivation

When you’re processing load test timings (or any latency distribution), you typically want buckets like p50/p95/p99 quickly. percently provides a small, fast Rust implementation exposed to Python.

Features

  • Fast: Rust core
  • Simple API: one call to compute a percentile
  • Python-friendly: works with regular lists/iterables of floats

Installation

Using uv:

uv add percently

Using pip:

pip install percently

🧮 Usage

import percently

data = [10.5, 22.0, 18.7, 19.2, 30.1, 25.3]

# Calculate the 95th percentile (f64)
p95 = percently.percentile(data, 95)
print(f"95th percentile: {p95:.2f}")

Streaming (iterative) percentile estimates

If you have a generator/iterable and want running percentile estimates without loading all values into memory, use stream.

import percently

def timings():
    for i in range(1, 1_000_001):
        yield float(i % 10_000) / 10_000.0

# Yield an updated p95 estimate every 1000 samples (approximate, bounded memory)
for est in percently.stream(timings(), 95, every=1000):
    last = est

print("final approx p95:", last)

Notes:

  • stream(..., 0, ...) yields the running min (exact)
  • stream(..., 100, ...) yields the running max (exact)
  • All values must be finite floats (no NaN/inf)

Development

Build/install locally (editable) with maturin:

uv sync
uv run maturin develop

Releasing

This repo is configured for signed release commits/tags and tag-based publishing:

  • Create a signed tag (e.g. 0.1.4)
  • GitHub Actions (tag-triggered) builds wheels/sdist and publishes to PyPI

Recommended (cargo-style) tool: cargo-release

cargo install cargo-release

# Patch release: bumps Cargo.toml version, commits (signed), creates signed tag, pushes
cargo release patch --execute

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

percently-0.1.4.tar.gz (68.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

percently-0.1.4-cp312-cp312-macosx_11_0_arm64.whl (201.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file percently-0.1.4.tar.gz.

File metadata

  • Download URL: percently-0.1.4.tar.gz
  • Upload date:
  • Size: 68.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.9.4

File hashes

Hashes for percently-0.1.4.tar.gz
Algorithm Hash digest
SHA256 1233c61c94e002ea659ed8ac34f0b397b24ba69703e34454d6cd0bb7c17c82ad
MD5 c5046be2c6b6dcade0acc080d8c96c0a
BLAKE2b-256 ff4ad9b41795758ea340e2ea13af2a2097e4d36abd1fa8ece2557b8dbc7bdb9a

See more details on using hashes here.

File details

Details for the file percently-0.1.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for percently-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 993b07d643cf305c58672567e16470aa6e01eb0fb9078844a967ba19158e93f4
MD5 c89f3a7e451ce5d0805b3b26bd984f3b
BLAKE2b-256 cd11a7cb2f17da40c522936ecce49716a8baaccb2546aefb481e7f755549c49b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page