SlideShare a Scribd company logo
1 of 33
Download to read offline
Dynamic Code Patterns:
                          Extending Your
                     Applications with Plugins
                         Doug Hellmann – @doughellmann – PyCon 2013




Saturday, March 16, 13                                                1
What is a “Plugin”?

                     • Loaded Dynamically
                     • Extends Core
                     • Possibly Unknown Source


Saturday, March 16, 13                           2
Why Plugins?

                     • Better API Abstraction
                     • Reduce Core Dependencies
                     • Strategy Pattern
                     • Visitor Pattern
                     • Indirect Code Contributions

Saturday, March 16, 13                               3
Ceilometer

                     • OpenStack Metering
                     • Measures Clouds
                     • Varied Billing Requirements
                     • Deployers Extend and Customize

Saturday, March 16, 13                                  4
Ceilometer Design
                                                                     Central
                                                                     Pollsters



                                                                     Compute             Meter Data
         Objects         Network        Volumes   Images   Compute
                                                                     Pollsters          Message Bus



                                                                      Event
                                                                     Listener
                                    Notification
                                   Message Bus


                                                                                 Collector




Saturday, March 16, 13                                                                                5
Ceilometer Design
                                                                     Central
                                                                     Pollsters



                                                                     Compute             Meter Data
         Objects         Network        Volumes   Images   Compute
                                                                     Pollsters          Message Bus



                                                                      Event
                                                                     Listener
                                    Notification
                                   Message Bus


                                                                                 Collector




Saturday, March 16, 13                                                                                5
Ceilometer Design
                                                                     Central
                                                                     Pollsters



                                                                     Compute             Meter Data
         Objects         Network        Volumes   Images   Compute
                                                                     Pollsters          Message Bus



                                                                      Event
                                                                     Listener
                                    Notification
                                   Message Bus


                                                                                 Collector




Saturday, March 16, 13                                                                                5
Ceilometer Design
                                                                     Central
                                                                     Pollsters



                                                                     Compute             Meter Data
         Objects         Network        Volumes   Images   Compute
                                                                     Pollsters          Message Bus



                                                                      Event
                                                                     Listener
                                    Notification
                                   Message Bus


                                                                                 Collector




Saturday, March 16, 13                                                                                5
Ceilometer Design
                                                                     Central
                                                                     Pollsters



                                                                     Compute             Meter Data
         Objects         Network        Volumes   Images   Compute
                                                                     Pollsters          Message Bus



                                                                      Event
                                                                     Listener
                                    Notification
                                   Message Bus


                                                                                 Collector




Saturday, March 16, 13                                                                                5
Ceilometer Design
                                                                     Central
                                                                     Pollsters



                                                                     Compute             Meter Data
         Objects         Network        Volumes   Images   Compute
                                                                     Pollsters          Message Bus



                                                                      Event
                                                                     Listener
                                    Notification
                                   Message Bus


                                                                                 Collector




Saturday, March 16, 13                                                                                5
Ceilometer Design
                                                                     Central
                                                                     Pollsters



                                                                     Compute             Meter Data
         Objects         Network        Volumes   Images   Compute
                                                                     Pollsters          Message Bus



                                                                      Event
                                                                     Listener
                                    Notification
                                   Message Bus


                                                                                 Collector




Saturday, March 16, 13                                                                                5
Ceilometer Design
                                                                     Central
                                                                     Pollsters



                                                                     Compute             Meter Data
         Objects         Network        Volumes   Images   Compute
                                                                     Pollsters          Message Bus



                                                                      Event
                                                                     Listener
                                    Notification
                                   Message Bus


                                                                                 Collector




Saturday, March 16, 13                                                                                5
Ceilometer Design
                                                                     Central
                                                                     Pollsters



                                                                     Compute             Meter Data
         Objects         Network        Volumes   Images   Compute
                                                                     Pollsters          Message Bus



                                                                      Event
                                                                     Listener
                                    Notification
                                   Message Bus


                                                                                 Collector




Saturday, March 16, 13                                                                                5
Ceilometer Plugins

                     • Message Bus
                     • Receiving Notifications
                     • Polling Compute
                     • Polling Other
                     • Storage

Saturday, March 16, 13                          6
Research
                     • Blogofile
                     • Sphinx              • Django
                                           • Pyramid
                     • Mercurial           • SQLAlchemy
                     • cliff
                     • virtualenvwrapper   • Diamond
                     • Nose                • Nova
                     • Trac
Saturday, March 16, 13                                    7
Discovery
                           Explicit         Scan

                                          Diamond
                    File   Mercurial
                                          Blogofile


                           Mercurial          Trac
          Import            Django            Nose
                           Pyramid
         Reference          Sphinx
                                               cliff
                                       virtualenvwrapper
                             Nova
Saturday, March 16, 13                                     8
Enabling
                          Explicit              Implicit

                            Django
                           Pyramid
                         SQLAlchemy
                                           virtualenvwrapper
                           Blogofile
                                                   cliff
                          Mercurial
                             Trac
                            Sphinx

Saturday, March 16, 13                                         9
Importing
                          Custom       pkg_resources

                            Django
                           Pyramid            Trac
                            Sphinx            Nose
                          Diamond        SQLAlchemy
                             Nova           Blogofile
                             Nose              cliff
                         SQLAlchemy    virtualenvwrapper
                           Blogofile

Saturday, March 16, 13                                     10
Integration
                              Fine           Coarse

                                Nose          Sphinx
           Prompt        virtualenvwrapper     Trac


                                             Mercurial
                               cliff         Blogofile
            Inspect         Diamond          Pyramid
                                              Django

Saturday, March 16, 13                                   11
Integration
                              Fine           Coarse

                                Nose          Sphinx
           Prompt        virtualenvwrapper     Trac


                                             Mercurial
                               cliff         Blogofile
            Inspect         Diamond          Pyramid
                                              Django

Saturday, March 16, 13                                   12
API Enforcement
                          Convention         Base Class / Interface


                              Blogofile
                              Mercurial          Nose (optional)
                               Django            Trac (interface)
                               Sphinx               Diamond
                              Pyramid               cliff (abc)
                         virtualenvwrapper


Saturday, March 16, 13                                                13
Invocation
                         Driver    Dispatcher      Iterator



                                    Mercurial
                                                       Nose
                SQLAlchemy           Django
                                                     Diamond
                   Nova             Pyramid
                                                virtualenvwrapper
                                      cliff



Saturday, March 16, 13                                              14
Discovery / Importing

                     • Entry Points
                     • Distribute and pkg_resources
                     • Be Consistent


Saturday, March 16, 13                                15
Enabling


                     • Explicit disabling
                     • Automatic disabling


Saturday, March 16, 13                       16
Integration

                     • Fine
                     • Inspect
                     • Application Owns Relationship


Saturday, March 16, 13                                 17
API Enforcement


                     • Abstract Base Classes
                     • Duck Typing


Saturday, March 16, 13                         18
Invocation

                     • Storage – Driver
                     • Notifications – Dispatcher
                     • Pollsters – Iterator


Saturday, March 16, 13                             19
stevedore


                     • Implements Patterns
                     • Wraps pkg_resources


Saturday, March 16, 13                       20
NamedExtensionManager


                     • Multiple Plugins
                     • Only Loads Named Plugins
                     • map()


Saturday, March 16, 13                            21
EnabledExtensionManager


                     • Multiple Plugins
                     • Checks Each with Function on Load
                     • map()


Saturday, March 16, 13                                     22
DispatchExtensionManager


                     • Multiple Plugins
                     • Invokes Subset on map()


Saturday, March 16, 13                           23
DriverManager


                     • Single Plugin
                     • Direct Access


Saturday, March 16, 13                     24
Dynamic Code Patterns:
                          Extending Your
                     Applications with Plugins
                         Doug Hellmann – @doughellmann – PyCon 2013

             http://packages.python.org/distribute/pkg_resources.html

             https://github.com/dreamhost/stevedore

             https://launchpad.net/ceilometer

             http://doughellmann.com

Saturday, March 16, 13                                                  25

More Related Content

More from doughellmann

How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
doughellmann
 

More from doughellmann (8)

How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
 
OpenStack 5th Birthday
OpenStack 5th BirthdayOpenStack 5th Birthday
OpenStack 5th Birthday
 
Regexes and-performance-testing
Regexes and-performance-testingRegexes and-performance-testing
Regexes and-performance-testing
 
OpenStack Atlanta-2014-12-18
OpenStack Atlanta-2014-12-18OpenStack Atlanta-2014-12-18
OpenStack Atlanta-2014-12-18
 
Taking the Long View: How the Oslo Program Reduces Technical Debt
Taking the Long View: How the Oslo Program Reduces Technical DebtTaking the Long View: How the Oslo Program Reduces Technical Debt
Taking the Long View: How the Oslo Program Reduces Technical Debt
 
Oslo Program Overview, OpenStack Atlanta
Oslo Program Overview, OpenStack AtlantaOslo Program Overview, OpenStack Atlanta
Oslo Program Overview, OpenStack Atlanta
 
Better Documentation Through Automation: Creating docutils & Sphinx Extensions
Better Documentation Through Automation: Creating docutils & Sphinx ExtensionsBetter Documentation Through Automation: Creating docutils & Sphinx Extensions
Better Documentation Through Automation: Creating docutils & Sphinx Extensions
 
An Introduction to the Zen of Python
An Introduction to the Zen of PythonAn Introduction to the Zen of Python
An Introduction to the Zen of Python
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Dynamic Code Patterns: Extending Your Applications with Plugins

  • 1. Dynamic Code Patterns: Extending Your Applications with Plugins Doug Hellmann – @doughellmann – PyCon 2013 Saturday, March 16, 13 1
  • 2. What is a “Plugin”? • Loaded Dynamically • Extends Core • Possibly Unknown Source Saturday, March 16, 13 2
  • 3. Why Plugins? • Better API Abstraction • Reduce Core Dependencies • Strategy Pattern • Visitor Pattern • Indirect Code Contributions Saturday, March 16, 13 3
  • 4. Ceilometer • OpenStack Metering • Measures Clouds • Varied Billing Requirements • Deployers Extend and Customize Saturday, March 16, 13 4
  • 5. Ceilometer Design Central Pollsters Compute Meter Data Objects Network Volumes Images Compute Pollsters Message Bus Event Listener Notification Message Bus Collector Saturday, March 16, 13 5
  • 6. Ceilometer Design Central Pollsters Compute Meter Data Objects Network Volumes Images Compute Pollsters Message Bus Event Listener Notification Message Bus Collector Saturday, March 16, 13 5
  • 7. Ceilometer Design Central Pollsters Compute Meter Data Objects Network Volumes Images Compute Pollsters Message Bus Event Listener Notification Message Bus Collector Saturday, March 16, 13 5
  • 8. Ceilometer Design Central Pollsters Compute Meter Data Objects Network Volumes Images Compute Pollsters Message Bus Event Listener Notification Message Bus Collector Saturday, March 16, 13 5
  • 9. Ceilometer Design Central Pollsters Compute Meter Data Objects Network Volumes Images Compute Pollsters Message Bus Event Listener Notification Message Bus Collector Saturday, March 16, 13 5
  • 10. Ceilometer Design Central Pollsters Compute Meter Data Objects Network Volumes Images Compute Pollsters Message Bus Event Listener Notification Message Bus Collector Saturday, March 16, 13 5
  • 11. Ceilometer Design Central Pollsters Compute Meter Data Objects Network Volumes Images Compute Pollsters Message Bus Event Listener Notification Message Bus Collector Saturday, March 16, 13 5
  • 12. Ceilometer Design Central Pollsters Compute Meter Data Objects Network Volumes Images Compute Pollsters Message Bus Event Listener Notification Message Bus Collector Saturday, March 16, 13 5
  • 13. Ceilometer Design Central Pollsters Compute Meter Data Objects Network Volumes Images Compute Pollsters Message Bus Event Listener Notification Message Bus Collector Saturday, March 16, 13 5
  • 14. Ceilometer Plugins • Message Bus • Receiving Notifications • Polling Compute • Polling Other • Storage Saturday, March 16, 13 6
  • 15. Research • Blogofile • Sphinx • Django • Pyramid • Mercurial • SQLAlchemy • cliff • virtualenvwrapper • Diamond • Nose • Nova • Trac Saturday, March 16, 13 7
  • 16. Discovery Explicit Scan Diamond File Mercurial Blogofile Mercurial Trac Import Django Nose Pyramid Reference Sphinx cliff virtualenvwrapper Nova Saturday, March 16, 13 8
  • 17. Enabling Explicit Implicit Django Pyramid SQLAlchemy virtualenvwrapper Blogofile cliff Mercurial Trac Sphinx Saturday, March 16, 13 9
  • 18. Importing Custom pkg_resources Django Pyramid Trac Sphinx Nose Diamond SQLAlchemy Nova Blogofile Nose cliff SQLAlchemy virtualenvwrapper Blogofile Saturday, March 16, 13 10
  • 19. Integration Fine Coarse Nose Sphinx Prompt virtualenvwrapper Trac Mercurial cliff Blogofile Inspect Diamond Pyramid Django Saturday, March 16, 13 11
  • 20. Integration Fine Coarse Nose Sphinx Prompt virtualenvwrapper Trac Mercurial cliff Blogofile Inspect Diamond Pyramid Django Saturday, March 16, 13 12
  • 21. API Enforcement Convention Base Class / Interface Blogofile Mercurial Nose (optional) Django Trac (interface) Sphinx Diamond Pyramid cliff (abc) virtualenvwrapper Saturday, March 16, 13 13
  • 22. Invocation Driver Dispatcher Iterator Mercurial Nose SQLAlchemy Django Diamond Nova Pyramid virtualenvwrapper cliff Saturday, March 16, 13 14
  • 23. Discovery / Importing • Entry Points • Distribute and pkg_resources • Be Consistent Saturday, March 16, 13 15
  • 24. Enabling • Explicit disabling • Automatic disabling Saturday, March 16, 13 16
  • 25. Integration • Fine • Inspect • Application Owns Relationship Saturday, March 16, 13 17
  • 26. API Enforcement • Abstract Base Classes • Duck Typing Saturday, March 16, 13 18
  • 27. Invocation • Storage – Driver • Notifications – Dispatcher • Pollsters – Iterator Saturday, March 16, 13 19
  • 28. stevedore • Implements Patterns • Wraps pkg_resources Saturday, March 16, 13 20
  • 29. NamedExtensionManager • Multiple Plugins • Only Loads Named Plugins • map() Saturday, March 16, 13 21
  • 30. EnabledExtensionManager • Multiple Plugins • Checks Each with Function on Load • map() Saturday, March 16, 13 22
  • 31. DispatchExtensionManager • Multiple Plugins • Invokes Subset on map() Saturday, March 16, 13 23
  • 32. DriverManager • Single Plugin • Direct Access Saturday, March 16, 13 24
  • 33. Dynamic Code Patterns: Extending Your Applications with Plugins Doug Hellmann – @doughellmann – PyCon 2013 http://packages.python.org/distribute/pkg_resources.html https://github.com/dreamhost/stevedore https://launchpad.net/ceilometer http://doughellmann.com Saturday, March 16, 13 25