extract-numbers
Extract numbers from strings, with support for commas, decimals, negatives, and the European format.
Installation
pip install extract-numbers
Usage
from extract_numbers import ExtractNumbers
extractor = ExtractNumbers()
text = "100,000 results found"
extractor.extractNumbers(text)
# => ['100,000']
API
ExtractNumbers(options: dict = None)
Create a new extractor instance with optional config.
.extractNumbers(text: str) -> List[Union[str, int, float]]
Extracts all valid numbers from the given string, based on the configured options.
Examples
Basic Extraction
extractor = ExtractNumbers()
extractor.extractNumbers("3030 results found")
# => ['3030']
extractor.extractNumbers("50 out of 100")
# => ['50', '100']
Negatives
extractor.extractNumbers("Temperature: -15°C, yesterday: -22, before: -20.5")
# => ['-15', '-22', '-20.5']
extractor.extractNumbers("-170,000, -222,987 and -222,987,899.70 respectively.")
# => ['-170,000', '-222,987', '-222,987,899.70']
Commas and Decimals
extractor.extractNumbers("100,000 out of 220,000,000 people")
# => ['100,000', '220,000,000']
extractor.extractNumbers("Your rating is 8.7")
# => ['8.7']
extractor.extractNumbers("Your balance: $100,000.77, previous: $90,899.89")
# => ['100,000.77', '90,899.89']
Options
Type: Object
as_string
Type: bool
Default: True
If set to False, all numbers are returned as int or float types.
ExtractNumbers({ 'as_string': False }).extractNumbers("7.7, 3030, 90,899,232.89 and -222,987,899.9")
# => [7.7, 3030, 90899232.89, -222987899.9]
remove_commas
Type: bool
Default: False
Works only when as_string=True.
Removes thousands separators from the returned number strings.
ExtractNumbers({ 'remove_commas': True }).extractNumbers("100,000,000 and -222,987,899.9")
# => ['100000000', '-222987899.9']
european_format
Type: bool
Default: False
Works only when as_string=True.
Enables European number formatting (e.g., 1.000.000,99 instead of 1,000,000.99).
ExtractNumbers({ 'european_format': True }).extractNumbers("1.000.000,77")
# => ['1.000.000,77']
ExtractNumbers({ 'european_format': True, 'as_string': False }).extractNumbers("1.000.000,77")
# => [1000000.77]
With remove_commas=True:
ExtractNumbers({ 'european_format': True, 'remove_commas': True }).extractNumbers("1.000.000,77")
# => ['1000000,77']
💡 Note: The decimal comma is preserved for
as_string=Trueto support formatting needs. Useas_string=Falseto convert to a float.
Contributing
Contributions, issues, and feature requests are welcome!
Feel free to:
- Fork the repo
- Create a new branch
- Submit a pull request
If you're fixing a bug or adding a feature, please include a clear description in your PR.
Ensure your changes are covered by tests.
Setup for Local Development
Install dev dependencies:
pip install .[dev]
OR
pip install '.[dev]'
Run the full validation suite (formatting, type checking, and tests):
make validate
Other Packages
- randomcoords – The Python client for the RandomCoords API to fetch random geographic coordinates worldwide.
License
MIT © Talha Awan
Metadata
Release files for extract-numbers 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| extract_numbers-1.0.2.tar.gz | 6.5 kB | Without provenance | Details for extract_numbers-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| extract_numbers-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for extract_numbers-1.0.2-py3-none-any.whl |
Total release size: 13.4 kB
Release files / extract_numbers-1.0.2.tar.gz
| Download URL | extract_numbers-1.0.2.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dfa834321f747ae5a6cc9ea3ccce694db46b36d5ccca6934bb65f4314baf84d2
|
|
BLAKE2b-256 checksum How to use checksums |
16875837b7c342d0807bd8520f8c3485ab671fb4e6cf06422b4bdb9827bc739d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.5
|
Release files / extract_numbers-1.0.2-py3-none-any.whl
| Download URL | extract_numbers-1.0.2-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e94a77c3bd37ccfd6a73b26a110ee08c19b62e30fb8e4de8c0be5e4a28bb97e
|
|
BLAKE2b-256 checksum How to use checksums |
f4564706fd8b399d2b67c6dc51ea74f2539c9c11cab9b849e2163459f051ea0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.5
|
Security for extract-numbers 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.