Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Import packages from "wrongly" named directories

Project Description


Impala is a PEP302 protocol (sys.meta_path hook for the import statement) implementation allowing the user to import packages and modules from arbitrarily named directories and files.


  • Comfort and freedom in development
  • Installed interface available without installation

Let’s say I’m developing a Python package called pyoneer. I want to lay the source code out like this:


The question then is, how do I import pyoneer in the test files (<workdir>/tests/...) and have it load <workdir>/src/ The default import mechanism requires packages to live in eponymous directories.

What’s the fuss about, you ask? I should simply rename the src directory to pyoneer or maybe src/pyoneer, no?

Indeed, this would be tolerable, at least with top-level packages. However, if I’m working on something that will be available as after installation, I certainly don’t want to wade through the desolate src/foo/bar to get to the source code.

Maybe I could import src in the tests instead? Well, tests are a form of documentation, and doubly so with doctest. “Proper” documentation (README.txt, etc) can also contain snippets which should be verifiable without the CUT being installed.

Impala to the rescue!

from os.path import abspath, dirname
import impala

root = abspath(dirname(__file__))

  pyoneer = '%s/src' % root

import pyoneer



aliases is a dict mapping from fully-qualified module/package names to paths to load from. To import a package p from path /a/b/c, aliases must include the key p with associated value /a/b/c, and /a/b/c/ must be a valid package entry point. To import a module m from path /f/g/, aliases must include the key m with associated value /f/g/


from os.path import abspath, dirname
import impala

r = dirname(abspath(__file__))

  'p': '%s/a/b/c' % r,
  'p.q': '%s/f/g/h' % r,
  'p.q.m': '%s/' % r,

import p
import p.q
import p.q.m


py-impala is distributed under the MIT license. See LICENSE for details.


Using pip from PyPI, the Python Package Index:

pip install impala

From a checkout or extracted tarball:

python install


Source code and issue tracker are at Github:

Release History

This version
History Node


History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(8.8 kB) Copy SHA256 Hash SHA256
Source None Oct 15, 2014

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers