natty

Python interface to Natty Date Parser


Keywords
natty
License
MIT
Install
pip install natty==0.2.3

Documentation

python-natty

A basic python wrapper for Natty, using Jpype.

Installation

$ pip install natty

You will also need to have a JVM installed and JAVA_HOME set properly for Jpype.

Usage

>>> from natty import DateParser
>>> dp = DateParser('tomorrow')
>>> dp.result()
[datetime.datetime(2015, 4, 12, 15, 53, 14, tzinfo=tzlocal())]
>>> dp = DateParser('monday and tuesday')
>>> dp.result()
[datetime.datetime(2015, 4, 13, 15, 53, 29, tzinfo=tzlocal()), datetime.datetime(2015, 4, 14, 15, 53, 29, tzinfo=tzlocal())]

If the string can be parsed for dates, the result returns a list of datetime objects with tzlocal timezone objects, as determined by the operating system. python-dateutil's parse method is used under the hood.

If the string cannot be parsed for any dates, it returns None.

Caveats

This is very rough and ready - it assumes a single DateGroup will be returned, although in fact Natty returns a list of DateGroups (although it only ever seems to contain a single DateGroup). If you are unsure about the result, you can check it on the Natty project site.

Thanks

Of course huge thanks to the creators of Natty, Jpype and dateutil, which are all awesome, but also thanks to python-boilerpipe which I copied for the project layout and use of Jpype.