A package for parsing number strings in various formats
Project description
numpar
A Python package for parsing human-friendly number formats into floats. Handles various number formats including comma separators, percentages, and magnitude suffixes (k, M, B).
Features
- Parse basic numbers with decimal points
- Support for comma-separated numbers (e.g., "1,234.56")
- Percentage conversion (e.g., "50%" → 0.5)
- Magnitude suffixes:
- k/K for thousands (e.g., "1.5k" → 1500)
- m/M for millions (e.g., "2.5M" → 2,500,000)
- b/B for billions (e.g., "1.5B" → 1,500,000,000)
- Whitespace handling
- Combined format support (e.g., "1,234.56k")
Installation
pip install numpar
Usage
from numpar import parse_number
# Basic numbers
parse_number('123.45') # 123.45
parse_number('-123.45') # -123.45
# Comma separators
parse_number('1,234.56') # 1234.56
parse_number('1,234,567') # 1234567.0
# Percentages
parse_number('50%') # 0.5
parse_number('12.34%') # 0.1234
# Magnitude suffixes
parse_number('1.5k') # 1500.0
parse_number('2.5M') # 2500000.0
parse_number('1.5B') # 1500000000.0
# Combined formats
parse_number('1,234.56k') # 1234560.0
Contributing
Contributions are welcome! Here's how you can help improve numpar:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run the tests locally:
# Install development dependencies pip install -e . # Run tests python -m unittest discover tests
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
-
Clone the repository:
git clone https://github.com/yourusername/numpar.git cd numpar
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate
-
Install in development mode:
pip install -e .
Publishing to PyPI
To publish a new version to PyPI:
-
Update version in
setup.py -
Build the distribution:
python -m pip install --upgrade build python -m build
-
Upload to PyPI:
python -m pip install --upgrade twine python -m twine upload dist/*
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file numpar-0.1.1.tar.gz.
File metadata
- Download URL: numpar-0.1.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
571f0de02c89795880da30bbf24a897c339e10d89ce04f026384fec2cbd6f85e
|
|
| MD5 |
39a90a888d024dc5fa4cc10e9aa3d758
|
|
| BLAKE2b-256 |
14ff8ccff7e7f7141b0f8d0a9d659ce1854d9d6c4ce64f1814ce0d68ad82e1f9
|
File details
Details for the file numpar-0.1.1-py3-none-any.whl.
File metadata
- Download URL: numpar-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cc0d25c288bb1b9a72d59510c064e0046ec096fe02437446f71ba1dc9378f8a
|
|
| MD5 |
0d08cc7af7ba67379bf45eb083a2bbef
|
|
| BLAKE2b-256 |
74ca12d5234be2002bb082f8f0a7e7b7a23ccb5ef67564e49183f108b6e85662
|