Sample lines from a stream.
Project description
sample-stream
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 add this directory to your PATH
or create an alias to this executable in a directory which already is on your PATH
.
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 [-h] [-W WEEKS] [-D DAYS] [-H HOURS] [-m MINUTES] [-s SECONDS]
[-t MILLISECONDS] [-u MICROSECONDS] [-r RATE] [-d DELAY]
[FILE]
Output lines from stdin to stdout with a given probability for a given duration, and with
a given delay between lines.
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
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.0}
}
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
Built Distribution
Hashes for sample_stream-0.2.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 166f7a8c97fe1d0a996591cebe14ce52cc7c8c8dbb06daa88ac3137e493b7fc6 |
|
MD5 | 9ce99410e28ab7c94dbc184ac25b598f |
|
BLAKE2b-256 | 131988bc29a8374d6b61e329b42c1e22dc1a196dfc4325c0c004ea67a4abcb68 |