Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 126315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:17:54+00:00 2026-05-11T05:17:54+00:00

I’m developing a python framework that would have addons written as separate packages. I.e.:

  • 0

I’m developing a python framework that would have ‘addons’ written as separate packages. I.e.:

import myframework from myframework.addons import foo, bar 

Now, what I’m trying to arrange is so that these addons can be distributed separately from core framework and injected into myframework.addons namespace.

Currently my best solution to this is the following. An add-on would be deployed (most likely into {python_version}/site-packages/ like so:

fooext/ fooext/__init__.py fooext/myframework/ fooext/myframework/__init__.py fooext/myframework/addons/ fooext/myframework/addons/__init__.py fooext/myframework/addons/foo.py 

The fooext/myframework/addons/__init__.py would have the pkgutil path extension code:

import pkgutil __path__ = pkgutil.extend_path(__path__, __name__) 

The problem is that for this to work, the PYTHONPATH needs to have fooext/ in it, however the only thing it would have is the parent install directory (most likely, the above-mentioned site-packages).

The solution to this is to have extra code in myframework/addons/__init__.py which would tranverse sys.path and look for any modules with a myframework sub-package, in which case it adds it to sys.path and everything works.

Another idea I had is to write the addon files directly to myframework/addons/ install location, but then it would make development and deployed namespace differ.

Is there a better way to accomplish this or perhaps a different approach to the above distribution problem altogether?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:17:54+00:00Added an answer on May 11, 2026 at 5:17 am

    Is there a better way to accomplish this or perhaps a different approach to the above distribution problem altogether?

    Possibly. Python’s module/package setup is generally tricky to tamper with dynamically like this, but its object/class system is open and extensible in a well-defined way. When modules and packages don’t quite have the features you need to encapsulate your project nicely you can use classes instead.

    For example you could have the extension functionality in a completely different package, but allow it to inject classes into your basic framework through a specific interface. eg. myframework/_​​_​init​_​​_.py containing a basic application wrapper:

    class MyFramework(object):     '''A bare MyFramework, I only hold a person's name     '''     _addons= {}     @staticmethod     def addAddon(name, addon):         MyFramework._addons[name]= addon      def __init__(self, person):         self.person= person         for name, addon in MyFramework._addons.items():             setattr(self, name, addon(self)) 

    Then you could have extension functionality in a myexts/helloer.py, that keeps a reference to its ‘owner’ or ‘outer’ MyFramework class instance:

    class Helloer(object):     def __init__(self, owner):         self.owner= owner     def hello(self):         print 'hello '+self.owner.person  import myframework myframework.MyFramework.addAddon('helloer', Helloer) 

    So now if you just ‘import myframework’, you only get the basic functionality. But if you also ‘import myexts.helloer’ you also get the ability to call MyFramework.helloer.hello(). Naturally you can also define protocols for addons to interact with the basic framework behaviour, and each other. You can also do things like inner classes a subclass of the framework can override to customise without having to monkey-patch classes that might affect other applications, if you need that level of complexity.

    Encapsulating behaviour like this can be useful, but it’s typically annoying work to adapt module-level code you’ve already got to fit this model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From the Qt for Open Source C++ development on Mac… May 11, 2026 at 11:47 pm
  • Editorial Team
    Editorial Team added an answer See this example: http://www.djangosnippets.org/snippets/1057/ Essentially, you can loop through a… May 11, 2026 at 11:47 pm
  • Editorial Team
    Editorial Team added an answer I'm not sure if I've missed something in your question,… May 11, 2026 at 11:47 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.