Sibling package imports
Question: I've tried reading through questions about sibling imports and even the
[package documentation](http://docs.python.org/tutorial/modules.html#intra-
package-references), but I've yet to find an answer.

With the following structure:

    
    
    ├── LICENSE.md
    ├── README.md
    ├── api
    │   ├── __init__.py
    │   ├── api.py
    │   └── api_key.py
    ├── examples
    │   ├── __init__.py
    │   ├── example_one.py
    │   └── example_two.py
    └── tests
    │   ├── __init__.py
    │   └── test_one.py
    

How can the scripts in the `examples` and `tests` directories import from the
`api` module and be run from the commandline?

Also, I'd like to avoid the ugly `sys.path.insert` hack for every file. Surely
this can be done in Python, right?


Answer: Here is another alternative that I insert at top of the Python files in
`tests` folder:

    
    
    # Path hack.
    import sys, os
    sys.path.insert(0, os.path.abspath('..'))
    

