SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
Tuesday, July 17, 12
What is Brubeck?
                       • A Mongrel2 Handler
                       • A Web Framework and Django
                        •  Influenced by Flask,Tornado

                       • A pipeline of coroutines
                       • Some coded opinions and a few libraries
                        •  Backend agnostic
                        •   Database agnostic
                        •   No spaghetti code



Tuesday, July 17, 12
What is a “Mongrel2”?
                       • A Mongrel2 is an asynchronous web server
                       • Delegatesthat part to external handlers
                                    handling
                         • We build
                         •   They communicate across 2 ZeroMQ sockets
                             •   Less processing than HTTP

                       • Language agnostic JSON or tnetstring
                         • Simple messaging via
                         •   ZeroMQ is language agnostic, thus so is Mongrel2



Tuesday, July 17, 12
Mongrel2 + A Handler
                                     Mongrel 2

                           Push / Pull                 Pub / Sub




                                         Handler
                                           Handler
                                             Handler



Tuesday, July 17, 12
What is a Mongrel2 Handler?

                       • Processes messages from Mongrel2
                         • Essentially, a Zed specific WSGI
                             •   There has been some dissent: Y U NO USE WSGI?

                       • Responds in HTTP
                       • A ZeroMQ sockets are language agnostic
                           language opinion
                         •
                         •   Zed chose Lua when he built Tir
                         •   I liked his model, but I like Python too
                         •   Lots of languages now supported



Tuesday, July 17, 12
Mongrel2 + Brubecks
                                    Mongrel 2

                          Push / Pull                 Pub / Sub




                                        Handler
                                          Handler
                                            Brubeck



Tuesday, July 17, 12
Hello world Take five!

                       class DemoHandler(WebMessageHandler):
                           def get(self):
                               self.set_body('Take five!')
                               return self.render()

                       urls = [('^/brubeck', DemoHandler)]




Tuesday, July 17, 12
Hello world Take five!
                  class DemoHandler(WebMessageHandler):
                      def get(self):
                          self.set_body('Take five!')
                          return self.render()

                  urls = [('^/brubeck', DemoHandler)]


            @app.add_route('^/brubeck', method='GET')
            def foo(application, message):
                body = 'Take five!'
                return render(body)




Tuesday, July 17, 12
Brubeck: routing
                                 Went with the usual style

                   class NameHandler(WebMessageHandler):
                       def get(self, name):
                           ...

                   def name_handler(application, message, name):
                       ...

                   urls = [(r'^/class/(w+)$', NameHandler),
                           (r'^/fun/(?Pw+)$', name_handler)]



           •       https://github.com/j2labs/brubeck/blob/master/demos/demo_urlargs.py



Tuesday, July 17, 12
Brubeck: templates
                       Supports: Jinja2, Mako,Tornado or Mustache
        from brubeck.templating import Jinja2Rendering

        class DemoHandler(WebMessageHandler, Jinja2Rendering):
            def get(self):
                context = {
                    'name': 'J2 D2',
                }
                return self.render_template('success.html', **context)




           •       https://github.com/j2labs/brubeck/blob/master/demos/demo_jinja2.py
           •       https://github.com/j2labs/brubeck/blob/master/demos/demo_mustache.py



Tuesday, July 17, 12
Brubeck: auth (pt 1)
               •       Simple example, using `web_authenticated` decorator:

        class DemoHandler(..., UserHandlingMixin):
            @web_authenticated
            def get(self):
                context = {
                    'name': self.current_user.username,
                }
                return self.render_template('some.html', **context)


          •       Also supports secure cookies
          •       Routes users to login template
          •       https://github.com/j2labs/brubeck/blob/master/demos/demo_login.py



Tuesday, July 17, 12
Brubeck: auth (pt 2)
         class BaseHandler(..., UserHandlingMixin):
             def get_current_user(self):
                 user = None
                 secret=self.application.cookie_secret
                 user_id = self.get_cookie('user_id', secret=secret)
                 if user_id:
                     return load_user(self.db_conn, username=user_id)
                 else:
                     username = self.get_argument('username')
                     password = self.get_argument('password')
                     if username:
                         user = load_user(self.db_conn, username=username)
                 if not user or not user.check_password(password):
                     return
                 return user




Tuesday, July 17, 12
Brubeck: user
               •       This what a Brubeck user model looks like

        class User(Document):
            username = StringField(max_length=30, required=True)
            password = StringField(max_length=128)
            is_active = BooleanField(default=False)
            last_login = LongField(default=curtime)
            date_joined = LongField(default=curtime)
            ...



          •       Uses UUID for id field
          •       Could use Mongo’s ObjectID if you prefer that
          •       https://github.com/j2labs/brubeck/blob/master/brubeck/models.py



Tuesday, July 17, 12
Brubeck: data validation
               •       Validation is easy

       >>> from brubeck.models import User
       >>> u = User(username='jd', is_active=True)
       >>> u.set_password('foo')
       >>> u.validate()
       >>> u.username = True
       >>> u.validate()
       Traceback (most recent call last):
       ...
       dictshield.base.ShieldException: Invalid value - username:True




Tuesday, July 17, 12
Databaseless modeling
               •       This what a Brubeck user looks like as Python


                       >>>   user_instance.to_python()
                       {
                             '_types': ['User'],
                             '_cls': 'User',
                             'username': u'jd',
                             'is_active': False,
                             'last_login': 1311718487532L,
                             'password': u'bcrypt|||salt|||hash',
                             'date_joined': 1311718487532L
                       }




Tuesday, July 17, 12
Databaseless modeling
                       •   Persistence details are up to you



            # Mongo
            >>> db.users.save(u.to_python())

            # Riak
            >>> user = bucket.new('user_key', data=u.to_python())
            >>> user.store()

            # Memcached
            >>> mc["user_key"] = u.to_json()




Tuesday, July 17, 12
Brubeck: autoapi
                       Automatic REST APIs from data models (!!)
                                  (Ben Beecher++)

              •        Define a DictShield document (our model)

              •        Define a QuerySet - Implements persistence
                  •     Dictionary based queryset is provided
                  •     Redis, Mongo and MySQL on the way
              •        Subclass AutoAPIBase
                  •     Attach your model as `model`
                  •     Attach your queryset as `queries`

              •        Register API for model in a Brubeck instance

Tuesday, July 17, 12
Brubeck: autoapi
                                        A Todo API
                       # Define Todo model
                       class Todo(Document):
                           completed = BooleanField(default=False)
                           deleted = BooleanField(default=False)
                           archived = BooleanField(default=False)
                           title = StringField(required=True)
                           ...

                       # Add fields to handler
                       class TodosAPI(AutoAPIBase):
                           queries = DictQueryset(db_conn={})
                           model = Todo

                       # Register with Brubeck instance
                       app.register_api(TodosAPI)


Tuesday, July 17, 12
Brubeck: autoapi
                $ curl -f 
                    -X POST 
                    -H "content-type: application/json" 
                    -d '{"text": "Watch more bsg", "order": 1}' 
                    http://localhost:6767/todo/

                {
                           "_cls": "Todo",
                           "_id": "111b4bb7-55f5-441b-ba25-c7a4fd99442c",
                           "_types": [
                               "Todo"
                           ],
                           "done": false,
                           "order": 1,
                           "text": "Watch more bsg"
                }




Tuesday, July 17, 12
Todos: backbone.js
                       AutoAPI works great with backbone.js
                            ( https://github.com/j2labs/todos )




Tuesday, July 17, 12
bpm
                          (brubeck project manager)
          $ bpm create project -n demo
          $ cd demo
          $ bpm create env
          $ bpm create env
          # Web Server
          ...
          Choose one (m2 wsgi): m2
          # Concurrency
          Choose one (gevent eventlet): gevent
          # Templating
          Choose one or more (jinja2 mako tornado mustache none): jinja2
          ...
          (demo) $




Tuesday, July 17, 12
Questions ??
               Brubeck: http://brubeck.io
               Code:    https://github.com/j2labs/brubeck

               Mongrel2: http://mongrel.org
               DictShield: https://github.com/j2labs/dictshield

               Gevent: http://gevent.org
               Eventlet: http://eventlet.net



Tuesday, July 17, 12

Contenu connexe

Tendances

Cassandra data modeling talk
Cassandra data modeling talkCassandra data modeling talk
Cassandra data modeling talkPatrick McFadin
 
Rails' Next Top Model
Rails' Next Top ModelRails' Next Top Model
Rails' Next Top ModelAdam Keys
 
Frontend Engineer Toolbox
Frontend Engineer ToolboxFrontend Engineer Toolbox
Frontend Engineer ToolboxYnon Perek
 
Groovy And Grails JUG Sardegna
Groovy And Grails JUG SardegnaGroovy And Grails JUG Sardegna
Groovy And Grails JUG SardegnaJohn Leach
 
What is NodeJS - Why Should You Care
What is NodeJS - Why Should You CareWhat is NodeJS - Why Should You Care
What is NodeJS - Why Should You Caregjj391
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaScott Hernandez
 
Standing on the shoulders of giants with JRuby
Standing on the shoulders of giants with JRubyStanding on the shoulders of giants with JRuby
Standing on the shoulders of giants with JRubyTheo Hultberg
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Guillaume Laforge
 
Java 7 Language Enhancement
Java 7 Language EnhancementJava 7 Language Enhancement
Java 7 Language Enhancementmuthusvm
 
Moose Design Patterns
Moose Design PatternsMoose Design Patterns
Moose Design PatternsYnon Perek
 
Annotations in PHP: They Exist
Annotations in PHP: They ExistAnnotations in PHP: They Exist
Annotations in PHP: They ExistRafael Dohms
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second LanguageRob Dunn
 
Security and performance designs for client-server communications
Security and performance designs for client-server communicationsSecurity and performance designs for client-server communications
Security and performance designs for client-server communicationsWO Community
 
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudy
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudyスローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudy
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudyYusuke Yamamoto
 
Practical introduction to dependency injection
Practical introduction to dependency injectionPractical introduction to dependency injection
Practical introduction to dependency injectionTamas Rev
 

Tendances (19)

Cassandra data modeling talk
Cassandra data modeling talkCassandra data modeling talk
Cassandra data modeling talk
 
Rails' Next Top Model
Rails' Next Top ModelRails' Next Top Model
Rails' Next Top Model
 
Frontend Engineer Toolbox
Frontend Engineer ToolboxFrontend Engineer Toolbox
Frontend Engineer Toolbox
 
Groovy And Grails JUG Sardegna
Groovy And Grails JUG SardegnaGroovy And Grails JUG Sardegna
Groovy And Grails JUG Sardegna
 
What is NodeJS - Why Should You Care
What is NodeJS - Why Should You CareWhat is NodeJS - Why Should You Care
What is NodeJS - Why Should You Care
 
Nio
NioNio
Nio
 
Intro to Sail.js
Intro to Sail.jsIntro to Sail.js
Intro to Sail.js
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with Morphia
 
Node.js 0.8 features
Node.js 0.8 featuresNode.js 0.8 features
Node.js 0.8 features
 
Standing on the shoulders of giants with JRuby
Standing on the shoulders of giants with JRubyStanding on the shoulders of giants with JRuby
Standing on the shoulders of giants with JRuby
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012
 
Java 7 Language Enhancement
Java 7 Language EnhancementJava 7 Language Enhancement
Java 7 Language Enhancement
 
Moose Design Patterns
Moose Design PatternsMoose Design Patterns
Moose Design Patterns
 
Annotations in PHP: They Exist
Annotations in PHP: They ExistAnnotations in PHP: They Exist
Annotations in PHP: They Exist
 
dojo.things()
dojo.things()dojo.things()
dojo.things()
 
Scripting as a Second Language
Scripting as a Second LanguageScripting as a Second Language
Scripting as a Second Language
 
Security and performance designs for client-server communications
Security and performance designs for client-server communicationsSecurity and performance designs for client-server communications
Security and performance designs for client-server communications
 
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudy
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudyスローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudy
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudy
 
Practical introduction to dependency injection
Practical introduction to dependency injectionPractical introduction to dependency injection
Practical introduction to dependency injection
 

En vedette

Microarmy - by J2 Labs
Microarmy - by J2 LabsMicroarmy - by J2 Labs
Microarmy - by J2 LabsJames Dennis
 
Brubeck: The Lightning Talk
Brubeck: The Lightning TalkBrubeck: The Lightning Talk
Brubeck: The Lightning TalkJames Dennis
 
Квартирный вопрос (3 рассказа для ознакомления)
Квартирный вопрос (3 рассказа для ознакомления)Квартирный вопрос (3 рассказа для ознакомления)
Квартирный вопрос (3 рассказа для ознакомления)Fantaversum Ph
 
Ведьмоспас. Евгений Лобачев (первые 4 главы для ознакомления)
Ведьмоспас. Евгений Лобачев (первые 4 главы для ознакомления)Ведьмоспас. Евгений Лобачев (первые 4 главы для ознакомления)
Ведьмоспас. Евгений Лобачев (первые 4 главы для ознакомления)Fantaversum Ph
 
ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsJames Dennis
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting PersonalKirsty Hulse
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldabaux singapore
 

En vedette (8)

Microarmy - by J2 Labs
Microarmy - by J2 LabsMicroarmy - by J2 Labs
Microarmy - by J2 Labs
 
Brubeck: The Lightning Talk
Brubeck: The Lightning TalkBrubeck: The Lightning Talk
Brubeck: The Lightning Talk
 
Квартирный вопрос (3 рассказа для ознакомления)
Квартирный вопрос (3 рассказа для ознакомления)Квартирный вопрос (3 рассказа для ознакомления)
Квартирный вопрос (3 рассказа для ознакомления)
 
Ведьмоспас. Евгений Лобачев (первые 4 главы для ознакомления)
Ведьмоспас. Евгений Лобачев (первые 4 главы для ознакомления)Ведьмоспас. Евгений Лобачев (первые 4 главы для ознакомления)
Ведьмоспас. Евгений Лобачев (первые 4 главы для ознакомления)
 
ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 Labs
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting Personal
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 

Similaire à Brubeck: Overview

Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mrubyHiroshi SHIBATA
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mrubyHiroshi SHIBATA
 
GR8Conf 2009: Groovy Usage Patterns by Dierk König
GR8Conf 2009: Groovy Usage Patterns by Dierk KönigGR8Conf 2009: Groovy Usage Patterns by Dierk König
GR8Conf 2009: Groovy Usage Patterns by Dierk KönigGR8Conf
 
node.js in production: Reflections on three years of riding the unicorn
node.js in production: Reflections on three years of riding the unicornnode.js in production: Reflections on three years of riding the unicorn
node.js in production: Reflections on three years of riding the unicornbcantrill
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...bobmcwhirter
 
Blocks & GCD
Blocks & GCDBlocks & GCD
Blocks & GCDrsebbe
 
Javascript, the GNOME way (JSConf EU 2011)
Javascript, the GNOME way (JSConf EU 2011)Javascript, the GNOME way (JSConf EU 2011)
Javascript, the GNOME way (JSConf EU 2011)Igalia
 
Implementing new WebAPIs
Implementing new WebAPIsImplementing new WebAPIs
Implementing new WebAPIsJulian Viereck
 
Leveraging zeromq for node.js
Leveraging zeromq for node.jsLeveraging zeromq for node.js
Leveraging zeromq for node.jsRuben Tan
 

Similaire à Brubeck: Overview (20)

Django at Scale
Django at ScaleDjango at Scale
Django at Scale
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
 
Grails 2.0 Update
Grails 2.0 UpdateGrails 2.0 Update
Grails 2.0 Update
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
 
GR8Conf 2009: Groovy Usage Patterns by Dierk König
GR8Conf 2009: Groovy Usage Patterns by Dierk KönigGR8Conf 2009: Groovy Usage Patterns by Dierk König
GR8Conf 2009: Groovy Usage Patterns by Dierk König
 
node.js in production: Reflections on three years of riding the unicorn
node.js in production: Reflections on three years of riding the unicornnode.js in production: Reflections on three years of riding the unicorn
node.js in production: Reflections on three years of riding the unicorn
 
Terrific Frontends
Terrific FrontendsTerrific Frontends
Terrific Frontends
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
Why Ruby?
Why Ruby? Why Ruby?
Why Ruby?
 
Blocks & GCD
Blocks & GCDBlocks & GCD
Blocks & GCD
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Javascript, the GNOME way (JSConf EU 2011)
Javascript, the GNOME way (JSConf EU 2011)Javascript, the GNOME way (JSConf EU 2011)
Javascript, the GNOME way (JSConf EU 2011)
 
MongoDB
MongoDBMongoDB
MongoDB
 
Implementing New Web
Implementing New WebImplementing New Web
Implementing New Web
 
Implementing new WebAPIs
Implementing new WebAPIsImplementing new WebAPIs
Implementing new WebAPIs
 
WebGL and three.js
WebGL and three.jsWebGL and three.js
WebGL and three.js
 
Everyday - mongodb
Everyday - mongodbEveryday - mongodb
Everyday - mongodb
 
Django a whirlwind tour
Django   a whirlwind tourDjango   a whirlwind tour
Django a whirlwind tour
 
Leveraging zeromq for node.js
Leveraging zeromq for node.jsLeveraging zeromq for node.js
Leveraging zeromq for node.js
 

Dernier

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Dernier (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Brubeck: Overview

  • 2. What is Brubeck? • A Mongrel2 Handler • A Web Framework and Django • Influenced by Flask,Tornado • A pipeline of coroutines • Some coded opinions and a few libraries • Backend agnostic • Database agnostic • No spaghetti code Tuesday, July 17, 12
  • 3. What is a “Mongrel2”? • A Mongrel2 is an asynchronous web server • Delegatesthat part to external handlers handling • We build • They communicate across 2 ZeroMQ sockets • Less processing than HTTP • Language agnostic JSON or tnetstring • Simple messaging via • ZeroMQ is language agnostic, thus so is Mongrel2 Tuesday, July 17, 12
  • 4. Mongrel2 + A Handler Mongrel 2 Push / Pull Pub / Sub Handler Handler Handler Tuesday, July 17, 12
  • 5. What is a Mongrel2 Handler? • Processes messages from Mongrel2 • Essentially, a Zed specific WSGI • There has been some dissent: Y U NO USE WSGI? • Responds in HTTP • A ZeroMQ sockets are language agnostic language opinion • • Zed chose Lua when he built Tir • I liked his model, but I like Python too • Lots of languages now supported Tuesday, July 17, 12
  • 6. Mongrel2 + Brubecks Mongrel 2 Push / Pull Pub / Sub Handler Handler Brubeck Tuesday, July 17, 12
  • 7. Hello world Take five! class DemoHandler(WebMessageHandler):     def get(self):         self.set_body('Take five!')         return self.render() urls = [('^/brubeck', DemoHandler)] Tuesday, July 17, 12
  • 8. Hello world Take five! class DemoHandler(WebMessageHandler):     def get(self):         self.set_body('Take five!')         return self.render() urls = [('^/brubeck', DemoHandler)] @app.add_route('^/brubeck', method='GET') def foo(application, message):     body = 'Take five!'     return render(body) Tuesday, July 17, 12
  • 9. Brubeck: routing Went with the usual style class NameHandler(WebMessageHandler):     def get(self, name):         ... def name_handler(application, message, name):     ... urls = [(r'^/class/(w+)$', NameHandler),         (r'^/fun/(?Pw+)$', name_handler)] • https://github.com/j2labs/brubeck/blob/master/demos/demo_urlargs.py Tuesday, July 17, 12
  • 10. Brubeck: templates Supports: Jinja2, Mako,Tornado or Mustache from brubeck.templating import Jinja2Rendering class DemoHandler(WebMessageHandler, Jinja2Rendering):     def get(self):         context = {             'name': 'J2 D2',         }         return self.render_template('success.html', **context) • https://github.com/j2labs/brubeck/blob/master/demos/demo_jinja2.py • https://github.com/j2labs/brubeck/blob/master/demos/demo_mustache.py Tuesday, July 17, 12
  • 11. Brubeck: auth (pt 1) • Simple example, using `web_authenticated` decorator: class DemoHandler(..., UserHandlingMixin): @web_authenticated def get(self):         context = {             'name': self.current_user.username,         }         return self.render_template('some.html', **context) • Also supports secure cookies • Routes users to login template • https://github.com/j2labs/brubeck/blob/master/demos/demo_login.py Tuesday, July 17, 12
  • 12. Brubeck: auth (pt 2) class BaseHandler(..., UserHandlingMixin):     def get_current_user(self):         user = None secret=self.application.cookie_secret         user_id = self.get_cookie('user_id', secret=secret)         if user_id:             return load_user(self.db_conn, username=user_id)         else:             username = self.get_argument('username')             password = self.get_argument('password')             if username:                 user = load_user(self.db_conn, username=username)         if not user or not user.check_password(password):             return         return user Tuesday, July 17, 12
  • 13. Brubeck: user • This what a Brubeck user model looks like class User(Document):     username = StringField(max_length=30, required=True)     password = StringField(max_length=128)     is_active = BooleanField(default=False)     last_login = LongField(default=curtime)     date_joined = LongField(default=curtime)     ... • Uses UUID for id field • Could use Mongo’s ObjectID if you prefer that • https://github.com/j2labs/brubeck/blob/master/brubeck/models.py Tuesday, July 17, 12
  • 14. Brubeck: data validation • Validation is easy >>> from brubeck.models import User >>> u = User(username='jd', is_active=True) >>> u.set_password('foo') >>> u.validate() >>> u.username = True >>> u.validate() Traceback (most recent call last): ... dictshield.base.ShieldException: Invalid value - username:True Tuesday, July 17, 12
  • 15. Databaseless modeling • This what a Brubeck user looks like as Python >>> user_instance.to_python() {     '_types': ['User'],     '_cls': 'User',     'username': u'jd',     'is_active': False,     'last_login': 1311718487532L,     'password': u'bcrypt|||salt|||hash',     'date_joined': 1311718487532L } Tuesday, July 17, 12
  • 16. Databaseless modeling • Persistence details are up to you # Mongo >>> db.users.save(u.to_python()) # Riak >>> user = bucket.new('user_key', data=u.to_python()) >>> user.store() # Memcached >>> mc["user_key"] = u.to_json() Tuesday, July 17, 12
  • 17. Brubeck: autoapi Automatic REST APIs from data models (!!) (Ben Beecher++) • Define a DictShield document (our model) • Define a QuerySet - Implements persistence • Dictionary based queryset is provided • Redis, Mongo and MySQL on the way • Subclass AutoAPIBase • Attach your model as `model` • Attach your queryset as `queries` • Register API for model in a Brubeck instance Tuesday, July 17, 12
  • 18. Brubeck: autoapi A Todo API # Define Todo model class Todo(Document):     completed = BooleanField(default=False)     deleted = BooleanField(default=False)     archived = BooleanField(default=False)     title = StringField(required=True)     ... # Add fields to handler class TodosAPI(AutoAPIBase):     queries = DictQueryset(db_conn={})     model = Todo # Register with Brubeck instance app.register_api(TodosAPI) Tuesday, July 17, 12
  • 19. Brubeck: autoapi $ curl -f -X POST -H "content-type: application/json" -d '{"text": "Watch more bsg", "order": 1}' http://localhost:6767/todo/ {     "_cls": "Todo",     "_id": "111b4bb7-55f5-441b-ba25-c7a4fd99442c",     "_types": [         "Todo"     ],     "done": false,     "order": 1,     "text": "Watch more bsg" } Tuesday, July 17, 12
  • 20. Todos: backbone.js AutoAPI works great with backbone.js ( https://github.com/j2labs/todos ) Tuesday, July 17, 12
  • 21. bpm (brubeck project manager) $ bpm create project -n demo $ cd demo $ bpm create env $ bpm create env # Web Server ... Choose one (m2 wsgi): m2 # Concurrency Choose one (gevent eventlet): gevent # Templating Choose one or more (jinja2 mako tornado mustache none): jinja2 ... (demo) $ Tuesday, July 17, 12
  • 22. Questions ?? Brubeck: http://brubeck.io Code: https://github.com/j2labs/brubeck Mongrel2: http://mongrel.org DictShield: https://github.com/j2labs/dictshield Gevent: http://gevent.org Eventlet: http://eventlet.net Tuesday, July 17, 12