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!

Automatically set the __package__ attribute of a script.

Project Description


Run modules inside packages as scripts. Automatically sets the __package__ attribute of any script which imports it and calls the initialization function set_package_attribute.init(). This is usually done so that the usual intra-package imports work for scripts inside packages.

For full documentation, see

Also available on PyPI for installation with pip.

Brief usage summary

To use the package just import it before any of the non-system files, inside any module that you might want to run as a script, and call the init function. These statements should be inside a guard conditional, so that they only run when the module is executed as a script:

if __name__ == "__main__":
    import set_package_attribute

Nothing else is required. The init function must be called before any within-package explicit relative imports, and before importing any modules from within the same package which themselves use such imports.

Release History

This version
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.

File Name & Hash SHA256 Hash Help Version File Type Upload Date
(6.0 kB) Copy SHA256 Hash SHA256
Source Jul 11, 2016

Supported By

WebFaction WebFaction Technical Writing 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 Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting