Introduction and Examples
The fuzzyparsers library provides a small collection of functions to sanitize free form user input. For the moment its chief value is the flexible date parser. The library strives to be locale smart in parsing dates.
The library has two main parsers. The first is a prefix parser which compares a string to a list of strings and returns the unique element of the list which matches the prefix. An exception is thrown if the match is not unique.
>>> from fuzzyparsers import fuzzy_match
>>> fuzzy_match(['aab','bba','abc'],'aa')
'aab'
>>> fuzzy_match(['aab','bba','abc'],'a') # two strings starting with 'a'.
Traceback (most recent call last):
...
ValueError: ambiguous match for 'a'
The second parser parses dates in various formats and returns a datetime.date object. Accepted formats include::
jan 12, 2003
jan 5
2004-3-5
+34 -- 34 days in the future (relative to todays date)
-4 -- 4 days in the past (relative to todays date)
For instance:
>>> from fuzzyparsers import parse_date
>>> parse_date('nov 30 2012') # my youngest son's birthday
datetime.date(2012, 11, 30)
The library allows setting a default date to fill in specified components of a date (e.g. the year). By default, a date with-out a year to will give the current year.
>>> from fuzzyparsers import DateParser
>>> import datetime
>>> DateParser(today=datetime.date(2013, 3, 1)).parse_date('feb 3')
datetime.date(2013, 2, 3)
TODO
We'd like to support the following features:
- Parsing time strings like "10 am" and "3 pm"
- A "[0-9].[0-9]" with the first hunk a month and the second hunk a day should return the month/day combination which is nearest. For example, "12-3" would return december 3 of this year or last year.
Changelog
- 0.9.5 - update revision control to git(hub) and minor regex fix
- 0.9.0 - support Python 3
- 0.8.0 - switch to MIT license because I couldn't figure out why I cared about GPL for this package.
- 0.7.3 - locale month-day order issues fixed (thanks to Treeve for getting this started.
- 0.7.2 - added doc-tests and "march 2012" date format; doc-test scripts
- 0.7.1 - install fixes
- 0.7 - overhaul of date parsing api to support relative dates (not necessarily relative to the current date)
- 0.6.x - initial public release and series of doc/install corrections
Installation
Fuzzyparsers is written by Joel B. Mohler and distributed under the terms of the MIT license.
Use the following commands to run the extensive doc-tests::
py.test fuzzyparsers --doctest-module
python -m doctest README.txt
To install fuzzyparsers, do the normal python thing (probably as root)::
python setup.py install
or::
pip install fuzzyparsers
Metadata
Release files for fuzzyparsers 0.9.5.1
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 |
|---|---|---|---|---|
| fuzzyparsers-0.9.5.1.tar.gz | 7.0 kB | Without provenance | Details for fuzzyparsers-0.9.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fuzzyparsers-0.9.5.1-py3-none-any.whl | Python 3 | none | any | Details for fuzzyparsers-0.9.5.1-py3-none-any.whl |
Total release size: 14.8 kB
Release files / fuzzyparsers-0.9.5.1.tar.gz
| Download URL | fuzzyparsers-0.9.5.1.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8529f9e1203e8d5e6ed622a77217d4ad9f8dcb9d2ba0f06ac1f8b8c44a3b30de
|
|
BLAKE2b-256 checksum How to use checksums |
5c565a090fae1c6f23c3d2ff3bceeed7973b54a5665f2b5166f866d3986ab01e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.2
|
Release files / fuzzyparsers-0.9.5.1-py3-none-any.whl
| Download URL | fuzzyparsers-0.9.5.1-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b0bf17cdf24bdd94dec3f9ab673fc2dce817879ce6e825d8be0824df89413b54
|
|
BLAKE2b-256 checksum How to use checksums |
6caa952ee53be50969020af50d08cbf6750f41299f649e84be13ea0d68bab663
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.2
|
Security for fuzzyparsers 0.9.5.1
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.