3.3.1 Extension names and packages

The first argument to the Extension constructor is always the name of the extension, including any package names. For example,

Extension("foo", ["src/foo1.c", "src/foo2.c"])
describes an extension that lives in the root package, while
Extension("pkg.foo", ["src/foo1.c", "src/foo2.c"])
describes the same extension in the pkg package. The source files and resulting object code are identical in both cases; the only difference is where in the filesystem (and therefore where in Python's namespace hierarchy) the resulting extension lives.

If you have a number of extensions all in the same package (or all under the same base package), use the ext_package keyword argument to setup(). For example,

setup(...
      ext_package = "pkg",
      ext_modules = [Extension("foo", ["foo.c"]),
                     Extension("subpkg.bar", ["bar.c"])]
     )
will compile foo.c to the extension pkg.foo, and bar.c to pkg.subpkg.bar.


See About this document... for information on suggesting changes.