No project description provided
Project description
primesieve-python
Summary
Python bindings for the primesieve C++ library.
Generates primes orders of magnitude faster than any pure Python code!
Features:
- Get an array of primes
- Iterate over primes using little memory
- Find the nth prime
- Count/print primes and prime k-tuplets
- Multi-threaded for counting primes and finding the nth prime
- NumPy support
Prerequisites
We provide primesieve wheels (distribution packages) for Windows, macOS and Linux for x86 and x64 CPUs. For other operating systems and/or CPUs you need to have installed a C++ compiler.
# Ubuntu/Debian
sudo apt install g++ python-dev
# Fedora
sudo dnf install gcc-c++ python-devel
# macOS
xcode-select --install
Installation
# Python 3.5 or later
pip install primesieve
# For Python 2.7 use:
pip install "primesieve<=1.4.4"
Conda Installation
You don't need to install a C++ compiler when installing python-primesieve using Conda.
conda install -c conda-forge python-primesieve
Usage examples
>>> from primesieve import *
# Get an array of the primes <= 40
>>> primes(40)
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
# Get an array of the primes between 100 and 120
>>> primes(100, 120)
[101, 103, 107, 109, 113]
# Get an array of the first 10 primes
>>> n_primes(10)
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
# Get an array of the first 10 primes >= 1000
>>> n_primes(10, 1000)
[1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061]
# Get the 10th prime
>>> nth_prime(10)
29
# Count the primes below 10**9
>>> count_primes(10**9)
50847534
Here is a list of all available functions.
Iterating over primes
Instead of generating a large array of primes and then do something with the primes it is also possible to simply iterate over the primes which uses less memory.
>>> import primesieve
it = primesieve.Iterator()
prime = it.next_prime()
# Iterate over the primes below 10000
while prime < 10000:
print prime
prime = it.next_prime()
# Set iterator start number to 100
it.skipto(100)
prime = it.prev_prime()
# Iterate backwards over the primes below 100
while prime > 0:
print prime
prime = it.prev_prime()
NumPy support
Using the primesieve.numpy
module you can generate an array of
primes using native C++ performance!
In comparison the primesieve
module generates an array of primes
about 3 times slower mostly because the conversion of the C primes
array into a python array is quite slow.
>>> from primesieve.numpy import *
# Generate a numpy array with the primes below 100
>>> primes(100)
array([ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,
61, 67, 71, 73, 79, 83, 89, 97])
# Generate a numpy array with the first 100 primes
>>> n_primes(100)
array([ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167,
173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239,
241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397,
401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467,
479, 487, 491, 499, 503, 509, 521, 523, 541])
Development
You need to have installed a C++ compiler, see Prerequisites.
# Install prerequisites
pip install cython pytest numpy
# Clone repository
git clone --recursive https://github.com/kimwalisch/primesieve-python
cd primesieve-python
# Build and install primesieve-python
pip install . --upgrade
# Run tests
pytest
How to do a new release
- You need to be a maintainer of the primesieve-python repo.
- You need to be a maintainer of the primesieve pypi project.
- Compare
.travis.yml
with cibuildwheel#example-setup and update.travis.yml
if needed. - Update the supported Python versions in
setup.py
(we support the same versions as cibuildwheel). - Increment the primesieve-python version in
setup.py
. Ideally this should be the last commit before the release as this uploads the new primesieve wheels to https://test.pypi.org. - Check if all primesieve wheels (Windows, macOS, Linux) have been uploaded to https://test.pypi.org.
- If not, read the Travis CI logs and fix the bugs.
- Finally, do a new release on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for primesieve-2.3.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a9c047f357a4b63b4cbb0d62cdab6a5a9e193d0a1e6609dd5c2563649cf6aed |
|
MD5 | 69980155444dd6dc436ed06ec32c19b5 |
|
BLAKE2b-256 | ef60a3743bcf075812e3d8e4b724ded5051dbe1eb023daf248d4ed3bf13e6c2e |
Hashes for primesieve-2.3.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19c9809756d7be5383546d262b8a0a44ea93e6431dc6d27b23bd59a95f9cc2c3 |
|
MD5 | f6d70e9b262bb21b325037289d1abec2 |
|
BLAKE2b-256 | 16e728cda9b85ab47d474051ea9598d1a589dbe8eeb8a4a7e67661e2edcda665 |
Hashes for primesieve-2.3.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 651850fc20c551e77bcc45e4617145ccc618ab6cd4b448fa7dcdb39ea720c018 |
|
MD5 | abd1fc9f258b045985b4a04f06f918f0 |
|
BLAKE2b-256 | df94fb20d4f2e87731fc16c871eda6df1e33255998fd1f931caceda1416c0e98 |
Hashes for primesieve-2.3.0-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fc6b0485e00618ed3a8a86ff2c01453f13810f5927cf64718502d205c2fc54a |
|
MD5 | ef3f9d04acbeb2679ea4003e38275c8f |
|
BLAKE2b-256 | ca7699183d445730c56b8e826755e3dd4bfcb849f5dc8ce754e30d098134c9f8 |
Hashes for primesieve-2.3.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2296fb4157533b16c83ce0275f25ebf13cbfe2990bce7154e4bddc73b1c6d7db |
|
MD5 | b330b0cf54bc981449b34dff33b55457 |
|
BLAKE2b-256 | 617586ee8f527a52890a70db5cbfed9cfd2727afac5da695104e55282ea8b270 |
Hashes for primesieve-2.3.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d066d21b18527d78b72bd411375c9027eaf873f9c2acf0280d8994677fec4d0 |
|
MD5 | b1eb71b3c32ab184c671d4b627d70549 |
|
BLAKE2b-256 | e63e17ac16a278e6eb903934eeecf86f79e0af401de604b2003d7855b611e768 |
Hashes for primesieve-2.3.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edf7392501591b125fe3f6083b2ecd2fdc6d98a27dcf566172acfa0d206d87d7 |
|
MD5 | 13001db2d372516ab5cde18e055cad14 |
|
BLAKE2b-256 | 60860f157e2b071461529909af1d0051ad702fdf57774aa4cba89d08b4341426 |
Hashes for primesieve-2.3.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bda9aca524b786fc9c1fc4649d9caaa6410f56a15e19c55d214520ab9d16331 |
|
MD5 | fe34ec4e9e3256ab7c3c6131d26f566e |
|
BLAKE2b-256 | 06d07b5c4cd96dd713640d0a2e1b537e90bf329e1f4c8ad41e7ae86226a3fe7e |
Hashes for primesieve-2.3.0-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdf98218dc50b0b900731a0d012946bc9c1b1e60471b2921e664ca93be60a33e |
|
MD5 | 6ad933d056f4877a9912f7e1a032d8bb |
|
BLAKE2b-256 | 1b8e089332f93a06c2ec86cfa489b7f1290579336d03503beb3ac5e1a5ab16e3 |
Hashes for primesieve-2.3.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86b32e459bfae3d1de00a00a8883b747849bf3bafc6cb5530d0417dc267bbd87 |
|
MD5 | e72f16d89bc749ca4d56ecd4df8636c1 |
|
BLAKE2b-256 | a302925ce483ed0c78126eff8c8805e9f245cb8fffdaa45213312e288c928cc5 |
Hashes for primesieve-2.3.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f8dfc4c37ca32a229d56119770cb8136dbd9fd188c4429bae3097bc1304ffcb |
|
MD5 | 0d28d1d3238c769babb4b32e34915ca3 |
|
BLAKE2b-256 | 09b492571419f2093a57d7b334e108dde7bc4cc8173d4c0e24ad50bee2479807 |
Hashes for primesieve-2.3.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30b1b056ed48cd5899e99238f2560a4ae192b11c15d00f60ef6e2f5a3983eb0c |
|
MD5 | 6c84df2e95ff263af3fee27d3d880955 |
|
BLAKE2b-256 | 6a355c84b4231f4d7e9389ca93ce938851109745f2b2a076dd7f9fabbccf40c1 |
Hashes for primesieve-2.3.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1f2b96523d33f10dae3a74fd4957cb85d4b0d818b7a44aa77f5d17f9a51c8cc |
|
MD5 | 43548fc27260406d117bc58a46203fbb |
|
BLAKE2b-256 | b6de1448bf7cdc39691a3291f49f3ffa86137b9dadb5bceb473bd482c493d1b7 |
Hashes for primesieve-2.3.0-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0c4d7c15fce14a8b414e0b720ded9f88a4f06d6af78343009886c9bec6cea7a |
|
MD5 | 256175007cd2ffc0b5d6392d5815d299 |
|
BLAKE2b-256 | 42fcf35ecf50c16e8873377e5cf18dc1c32c1375b1ae6bb368a5b167c0213dec |
Hashes for primesieve-2.3.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b677e264df33ff442e1c53c81cdbfbbb7bd3bdc92d2bb94b5893d861e6912563 |
|
MD5 | b8f4d5c2da3682c0b22aaeca6a7c4059 |
|
BLAKE2b-256 | 16c485d1a539afb0905a090c5a94c0600d907507a92675f54b59a1712dfdb47b |
Hashes for primesieve-2.3.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 419e407039c291d13edd16221f5422e745607ee66286fe7884ddaaf087bb5f2b |
|
MD5 | cd0d177902c6f50643ff7f702c1c3768 |
|
BLAKE2b-256 | cd5f8ca416f7685b3a28a495d93ad9d46d54a57576ef05b8f91fa5214a8486ea |
Hashes for primesieve-2.3.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf1768d7b50f817006f923695e862027a980d34b2494536b394de31db94ed052 |
|
MD5 | e50d31345a0b928cc0bac2c56c1f2eaf |
|
BLAKE2b-256 | f8b875f2a5c6eaf01df1d9180c32536be6180b402a2d95f6a375d05de7c1b9b6 |
Hashes for primesieve-2.3.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 027e08bffcfacd40973707797cc2e81199e3d639b901372c9e1a73737e6ba72f |
|
MD5 | 5c0525e8a5220016671c9bcfb92e2ca7 |
|
BLAKE2b-256 | 448ebc8aebd96cd5608fa0d8d757a09136e1b208482758824b69c48ebd28a205 |
Hashes for primesieve-2.3.0-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b394000dbd4ac76122173d15057595c4b51143dc3e02758a1305f12bee3c4f4f |
|
MD5 | c768f4d43fd4cb38797d3dd275196e67 |
|
BLAKE2b-256 | 96aa7a942abf8ee9ce1bb25b0e9a68d71313b53a4360e1f048fe7e7bd48b61ee |
Hashes for primesieve-2.3.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2682490caabb710f51421426bdaa486982d5cdf531827be41c1510e319b69a1 |
|
MD5 | 89f6274b9ce1a954db4760cb87275a05 |
|
BLAKE2b-256 | b895a8cd7897cd66ef2b7bbe4ce50e3569a27464bde28af2487ddc3bc9fd6c4a |
Hashes for primesieve-2.3.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9953d4f360c8b6cdc570765cf00e4a8c486ee41aeab7e6f8ad556816bebfd17 |
|
MD5 | b09d3281a4085672f801e9963bc11855 |
|
BLAKE2b-256 | 186f0d0a362e4ed1f1e158f242468062875fe7872f292b3117e3e6ba7fbdfd63 |
Hashes for primesieve-2.3.0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4440a34e7b8d08d0eb31724eb2675fdac4045cfd0bcfd3519b623fef83f22642 |
|
MD5 | fa8dd428a0ea4e9d7413004ff538902d |
|
BLAKE2b-256 | 59984084f8ef2d41e2e39355ac39f9dc8b1bbef7aca955b7285b3ceeddb1c7eb |
Hashes for primesieve-2.3.0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69ca0b31b56b9b2a4bd6bb381939fa1d05b79399312ca52c816803e199eb3045 |
|
MD5 | 19593635606b55e65f43feb532e43ad7 |
|
BLAKE2b-256 | 09e583a97c8853aeed4db496a676e19215fe5a90e919f267438c7d96943d7c5b |
Hashes for primesieve-2.3.0-cp35-cp35m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 432b99a8cda932e975dfc78faa63747f8409734af6ea3e023882692eece3c51d |
|
MD5 | 0fecfdad2202c1a627c52bc628e6da14 |
|
BLAKE2b-256 | b71213164622ecf9ad44fbd01364a13098028483a51c1ca70f2f6f0b23ccef97 |
Hashes for primesieve-2.3.0-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca39229bee22b5e0a903ceee948d39032fb323851e8aebcf9a575c692e3787e9 |
|
MD5 | 51806e11c71d2c06ac51b98d274ea91a |
|
BLAKE2b-256 | 71ecff648686d33e90e39a61ed57e50f2a8970a8c0dc59c5d6badd3db4dfccf8 |