Welcome to apipkg!

With apipkg you can control the exported namespace of a
python package and greatly reduce the number of imports for your users.
It is a small pure python module that works on virtually all Python
versions, including CPython2.3 to Python3.1, Jython and PyPy. It co-operates
well with Python's help() system, custom importers (PEP302) and common
command line completion tools.

Usage is very simple: you can require 'apipkg' as a dependency or you
can copy paste the <200 Lines of code into your project.

Tutorial example

Here is a simple mypkg package that specifies one namespace
and exports two objects imported from different modules:

You need to create a _mypkg package with a somemodule.py
and othermodule.py containing the respective classes.
The _mypkg is not special - it's a completely
regular python package.

Namespace dictionaries contain name: value mappings
where the value may be another namespace dictionary or
a string specifying an import location. On accessing
an namespace attribute an import will be performed:

The mypkg.path namespace and its two entries are
loaded when they are accessed. This means:

lazy loading - only what is actually needed is ever loaded

only the root "mypkg" ever needs to be imported to get
access to the complete functionality.

the underlying modules are also accessible, for example:

from mypkg.sub import Class1

Including apipkg in your package

If you don't want to add an apipkg dependency to your package you
can copy the apipkg.py file somewhere to your own package,
for example _mypkg/apipkg.py in the above example. You
then import the initpkg function from that new place and
are good to go.