I have a very simple package, which I eventually want to release through PyPI, which has a directory tree like the following:
daterangeparser/
__init__.py
parse_date_range.py
test.py
parse_date_range.py defines a function called parse.
What is the easiest and most pythonic way for me to set up the package for easy importing of the parse function, and how can I do it?
At the moment I have to do from daterangeparser.parse_date_range import parse which seems rather clunky. I’d rather do from daterangeparser import parse, which seems simpler and more pythonic, but I can’t seem to work out how to get this to work (do I need to put something else in __init__.py? Or, is there a better way to do this?
Do you really need
parse_date_rangemodule? The package namedaterangeparseralready conveys the intent,daterangeparser.parse_date_rangedoesn’t make any sense.You can move all the code from
parse_date_rangemodule to__init__and then you can importparselikefrom daterangeparser import parse.