Skip to main content

Filter lines from standard input according to some probability, with a given delay, and for a certain duration.

Project description

sample-stream

Build status Python Version Dependencies Status

Code style: black Security: bandit Pre-commit Semantic Versions License

sample is a Python package that allows you to filter lines from standard input according to some probability, with a given delay, and for a certain duration.

Installation

You can install sample-stream as follows:

$ python -m pip install sample-stream

This will install an executable sample in ~/.local/bin. You probably want to either (1) add this directory to your PATH, (2) create a symlink to this executable in a directory which already is on your PATH, or (3) use an alias.

Example

The following command samples lines with a probability of 0.01, with a delay of 1000 milliseconds in between lines, for 5 seconds.

$ time seq -f "Line %g" 1000000 | sample -r 1% -d 1000 -s 5
Line 71
Line 250
Line 305
Line 333
Line 405
Line 427
seq -f "Line %g" 1000000  0.01s user 0.00s system 0% cpu 5.092 total
sample -r 1% -d 1000 -s 5  0.06s user 0.02s system 1% cpu 5.091 total

Help

$ sample --help
usage: sample-stream [-h] [-W WEEKS] [-D DAYS] [-H HOURS] [-m MINUTES]
                     [-s SECONDS] [-t MILLISECONDS] [-u MICROSECONDS]
                     [-r RATE] [-d DELAY]
                     [FILE]

Filter lines from standard input according to some probability, with a
given delay, and for a certain duration.

positional arguments:
  FILE                  File

optional arguments:
  -h, --help            show this help message and exit
  -W WEEKS, --weeks WEEKS
                        Duration of sampling in weeks
  -D DAYS, --days DAYS  Duration of sampling in days
  -H HOURS, --hours HOURS
                        Duration of sampling in hours
  -m MINUTES, --minutes MINUTES
                        Duration of sampling in minutes
  -s SECONDS, --seconds SECONDS
                        Duration of sampling in seconds
  -t MILLISECONDS, --milliseconds MILLISECONDS
                        Duration of sampling in milliseconds
  -u MICROSECONDS, --microseconds MICROSECONDS
                        Duration of sampling in microseconds
  -r RATE, --rate RATE  Rate between 0 and 1 using either 0.33, 33%,
                        1/3 notation.
  -d DELAY, --delay DELAY
                        Time in milliseconds between each line of
                        output

License

License

This project is licensed under the terms of the MIT license. See LICENSE for more details.

Citation

@software{sample-stream,
  author = {Jeroen H.M. Janssens},
  title = {{sample-stream} -- Sample lines from a stream},
  year = {2021},
  url = {https://github.com/jeroenjanssens/sample-stream},
  version = {0.2.5}
}

Credits

This project was generated with python-package-template.

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

sample-stream-0.2.5.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

sample_stream-0.2.5-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file sample-stream-0.2.5.tar.gz.

File metadata

  • Download URL: sample-stream-0.2.5.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.1 Darwin/20.2.0

File hashes

Hashes for sample-stream-0.2.5.tar.gz
Algorithm Hash digest
SHA256 2cd7052b3a81f9af134479d6876828daf96a3fcd024e3397f64eb1e9c61bec86
MD5 13723d473cf3a014df9d260719e55915
BLAKE2b-256 a46d3fcf4ca90a8c00077c4fef1150e01758850f97fcdaca231c6ed3d83ca308

See more details on using hashes here.

File details

Details for the file sample_stream-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: sample_stream-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.1 Darwin/20.2.0

File hashes

Hashes for sample_stream-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c5fe787ed7f9400e981bd81474fdb468878cea99159866103b1867a2a6d8c7cd
MD5 ac3742b918fb279a0abc55b47f8ab85c
BLAKE2b-256 1dc84f81165c2d641df8cf858adc8531270a82473000200da6a9e0114ef30377

See more details on using hashes here.

Supported by

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