apipkg

Namespace control and lazy-import mechanism
Download

apipkg Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Holger Krekel
  • Publisher web site:
  • http://twitter.com/hpk42

apipkg Tags


apipkg Description

Namespace control and lazy-import mechanism apipkg is a library that allows you to 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 >> import mypkg>>> mypkg.path< ApiModule 'mypkg.path '>>>> mypkg.sub.Class1 # '_mypkg.somemodule' gets imported now< class _mypkg.somemodule.Class1 at 0xb7d428fc >>>> mypkg.sub.Class2 # '_mypkg.othermodule' gets imported now< class _mypkg.somemodule.Class1 at 0xb7d428fc >The mypkg.sub namespace and both its classes are lazy loaded. Note that no imports apart from the root 'import mypkg' is required. This means that whoever uses your Api only ever needs this one import. Of course you can still use the import statement like so:from mypkg.sub import Class1Including apipkg in your packageIf 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. Requirements: · Python


apipkg Related Software