Skip to main content

PrimeForge - A Python module for working with prime numbers.

Project description

PrimeForge

A Python module for working with prime numbers. This module provides various functions to generate, check, and manipulate prime numbers.

Installation

You can install this module using:

pip install primeforge

Features

  • Generate prime numbers within a range
  • Check if a number or a sequence of numbers are prime
  • Find the next or previous prime number
  • Generate random prime numbers
  • Find the prime factors of a number
  • Remove or filter prime numbers from a sequence

Usage

Importing the module

from primeforge import *

Functions

primes(start: int, stop: int) -> list

Returns a list of prime numbers in the range [start, stop).

primes(10, 30)  # [11, 13, 17, 19, 23, 29]

copyprimes(seq: list) -> list

Returns a list containing only the prime numbers from the given sequence.

copyprimes([10, 11, 12, 13, 14, 15])  # [11, 13]

deleteprimes(lst: list) -> None

Removes all prime numbers from the given list (modifies in place).

nums = [10, 11, 12, 13, 14, 15]
deleteprimes(nums)
print(nums)  # [10, 12, 14, 15]

withoutprimes(seq: list) -> list

Returns a new list with all prime numbers removed.

withoutprimes([10, 11, 12, 13, 14, 15])  # [10, 12, 14, 15]

isprime(number: int) -> bool

Checks if a number is prime.

isprime(11)  # True
isprime(10)  # False

isprimes(seq: list) -> bool

Checks if all numbers in the sequence are prime.

isprimes([11, 13, 17])  # True
isprimes([11, 14, 17])  # False

nextprime(number: int) -> int

Finds the next prime number greater than the given number.

nextprime(10)  # 11

prevprime(number: int) -> int | None

Finds the largest prime number smaller than the given number. Returns None if there is no previous prime.

prevprime(10)  # 7
prevprime(2)   # None

randprime(start: int, stop: int, count: int = 1, replacement: bool = True) -> list

Returns a list of random prime numbers in the range [start, stop).
If replacement is True, numbers may repeat. Otherwise, unique numbers are selected.

randprime(10, 50, 3)  # Example: [13, 37, 19]

primefactors(number: int) -> list | None

Returns a list of prime factors of a number. Returns None for 0, 1, or non-integer values.

primefactors(60)  # [2, 2, 3, 5]
primefactors(13)  # [13]

License

This project is licensed under the MIT License.

Copyright 2025 Rishikesh

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

primeforge-1.0.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

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

primeforge-1.0.0-py2.py3-none-any.whl (4.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file primeforge-1.0.0.tar.gz.

File metadata

  • Download URL: primeforge-1.0.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for primeforge-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b6ae35c0e8c301c767a0ead9e5ae3010508ce0154c284db7987e82f11a9094d5
MD5 d1ef694380b4d53ce90aa72fe8ca721a
BLAKE2b-256 2c07524dfd06679258b752428aa91e72151b29093c75f597c82b4c24fb27094a

See more details on using hashes here.

File details

Details for the file primeforge-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: primeforge-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for primeforge-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 150ab7d36ecd96f8b957a7ff6c49a9766d375591b2994926da020269f106b4cc
MD5 1a026e7903fda2f4821ea75112721baf
BLAKE2b-256 d4ffa8e5b86562189ca10af1fd7a8190e28285e85d565d76101abc56876705ac

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