0
<ul>Introduction to Spring Python </ul><ul>Greg L. Turnquist Senior Software Engineer <li>SpringSource </li></ul><ul>Adapt...
<ul>What should you take away from this? </ul><ul><li>Spring Python gives you the tools to build dynamic, powerful, easy-t...
<ul>Who Am I? </ul><ul><li>A test-bitten script junky, always seeking better solutions for customer requirements
Worked as a software engineer for 11 years at Harris Corporation after graduating Auburn University with Master's in Compu...
Have built mission critical systems, trained on-call support teams, evangelized usage of wikis, and utilized Agile practic...
Active contributor to open source community: MythTV, Mediawiki, Spring Framework/Acegi, TestNG Eclipse plug-in
Find me at http://www.linkedin.com/in/GregLTurnquist </li></ul>
<ul>Who Am I? </ul><ul><li>Wrote  Spring Python 1.1
Find detailed diagrams, lots of code examples, and information on how to build powerful Python applications using the Spri...
http://springpythonbook.com </li></ul>
<ul>The Spring Framework provides many useful features, and I wanted those same features available in Python. </ul>
<ul>Agenda </ul><ul><li>History
Technology </li></ul><ul><ul><li>IoC container
Database template
Transactions
Security
AOP
Remoting </li></ul></ul><ul><li>Status </li></ul><ul><ul><li>Current
Future of the project </li></ul></ul>
<ul>When/where did it come from? </ul><ul><li>In October 2006 came the carputer
Needed utility of Spring with power of Python
In December 2006, made first release to Sourceforge
In July 2008, Russ Miles (SpringSource) invited Spring Python to be a Spring Extension
In June 2009, started writing Python 1.1 book </li></ul>
<ul>Becoming an extension </ul><ul><li>Since then: </li></ul><ul><ul><li>Migrated code to Spring's subversion servers, and...
Worked with build team to setup Continuous Integration
Copied all tickets into JIRA (open and closed)‏
Setup Spring Python community forum, blog, and irc channel (#springpython)
Made 750+ commits; released versions 0.6-0.9, 1.0, and 1.1; closed 109 issues
Brought on board two more committers
Currently interacting w/many devs and users about future of Spring Python including roadmap for 1.2 and beyond </li></ul><...
<ul>Agenda </ul><ul><li>History
Technology </li></ul><ul><ul><li>IoC container
Database template
Transactions
Security
AOP
Remoting </li></ul></ul><ul><li>Status </li></ul><ul><ul><li>Current
Future of the project </li></ul></ul>
<ul>We have the same concepts as Spring </ul><ul>Simple Object </ul><ul>Simple Object </ul><ul>Dependency Injection </ul><...
<ul>Multiple IoC formats supported </ul><ul><li>Started with an XML-based configuration
Later, a python decorator-based configuration
Recently rewrote IoC container, handles: </li></ul><ul><ul><li>Original format (now called PyContainerConfig)‏
Newer, more sophisticated XML format (XMLConfig)‏
Spring Java's format (SpringJavaConfig)‏
Decorator-based @Object format (PythonConfig)
YAML-based format (YamlConfig)‏ </li></ul></ul>
<ul>New container can mix ANYTHING </ul><ul><li>Allows multiple sources in multiple formats
Objects can reference ANY other object </li></ul><ul><ul><li>...no matter WHERE its defined
Upcoming SlideShare
Loading in...5
×

Intro To Spring Python

7,948

Published on

This is an adaptation of the presentation given at the SpringOne 2008 conference in Hollywood, FL. It contains some updates on project status, and also information about the recently published book "Spring Python 1.1"

This slideshow is licensed under a Creative Commons Attribution 3.0 United States License.

Published in: Technology
1 Comment
5 Likes
Statistics
Notes
No Downloads
Views
Total Views
7,948
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
112
Comments
1
Likes
5
Embeds 0
No embeds

No notes for slide

Transcript of "Intro To Spring Python"

  1. 1. <ul>Introduction to Spring Python </ul><ul>Greg L. Turnquist Senior Software Engineer <li>SpringSource </li></ul><ul>Adapted from presentation given at SpringOne 2008 </ul>
  2. 2. <ul>What should you take away from this? </ul><ul><li>Spring Python gives you the tools to build dynamic, powerful, easy-to-maintain enterprise solutions </li></ul>
  3. 3. <ul>Who Am I? </ul><ul><li>A test-bitten script junky, always seeking better solutions for customer requirements
  4. 4. Worked as a software engineer for 11 years at Harris Corporation after graduating Auburn University with Master's in Computer Engineering. Joined SpringSource in 2010.
  5. 5. Have built mission critical systems, trained on-call support teams, evangelized usage of wikis, and utilized Agile practices to write top quality software
  6. 6. Active contributor to open source community: MythTV, Mediawiki, Spring Framework/Acegi, TestNG Eclipse plug-in
  7. 7. Find me at http://www.linkedin.com/in/GregLTurnquist </li></ul>
  8. 8. <ul>Who Am I? </ul><ul><li>Wrote Spring Python 1.1
  9. 9. Find detailed diagrams, lots of code examples, and information on how to build powerful Python applications using the Spring way.
  10. 10. http://springpythonbook.com </li></ul>
  11. 11. <ul>The Spring Framework provides many useful features, and I wanted those same features available in Python. </ul>
  12. 12. <ul>Agenda </ul><ul><li>History
  13. 13. Technology </li></ul><ul><ul><li>IoC container
  14. 14. Database template
  15. 15. Transactions
  16. 16. Security
  17. 17. AOP
  18. 18. Remoting </li></ul></ul><ul><li>Status </li></ul><ul><ul><li>Current
  19. 19. Future of the project </li></ul></ul>
  20. 20. <ul>When/where did it come from? </ul><ul><li>In October 2006 came the carputer
  21. 21. Needed utility of Spring with power of Python
  22. 22. In December 2006, made first release to Sourceforge
  23. 23. In July 2008, Russ Miles (SpringSource) invited Spring Python to be a Spring Extension
  24. 24. In June 2009, started writing Python 1.1 book </li></ul>
  25. 25. <ul>Becoming an extension </ul><ul><li>Since then: </li></ul><ul><ul><li>Migrated code to Spring's subversion servers, and later to git
  26. 26. Worked with build team to setup Continuous Integration
  27. 27. Copied all tickets into JIRA (open and closed)‏
  28. 28. Setup Spring Python community forum, blog, and irc channel (#springpython)
  29. 29. Made 750+ commits; released versions 0.6-0.9, 1.0, and 1.1; closed 109 issues
  30. 30. Brought on board two more committers
  31. 31. Currently interacting w/many devs and users about future of Spring Python including roadmap for 1.2 and beyond </li></ul></ul>
  32. 32. <ul>Agenda </ul><ul><li>History
  33. 33. Technology </li></ul><ul><ul><li>IoC container
  34. 34. Database template
  35. 35. Transactions
  36. 36. Security
  37. 37. AOP
  38. 38. Remoting </li></ul></ul><ul><li>Status </li></ul><ul><ul><li>Current
  39. 39. Future of the project </li></ul></ul>
  40. 40. <ul>We have the same concepts as Spring </ul><ul>Simple Object </ul><ul>Simple Object </ul><ul>Dependency Injection </ul><ul>AOP </ul><ul>Portable Service Abstractions </ul>
  41. 41. <ul>Multiple IoC formats supported </ul><ul><li>Started with an XML-based configuration
  42. 42. Later, a python decorator-based configuration
  43. 43. Recently rewrote IoC container, handles: </li></ul><ul><ul><li>Original format (now called PyContainerConfig)‏
  44. 44. Newer, more sophisticated XML format (XMLConfig)‏
  45. 45. Spring Java's format (SpringJavaConfig)‏
  46. 46. Decorator-based @Object format (PythonConfig)
  47. 47. YAML-based format (YamlConfig)‏ </li></ul></ul>
  48. 48. <ul>New container can mix ANYTHING </ul><ul><li>Allows multiple sources in multiple formats
  49. 49. Objects can reference ANY other object </li></ul><ul><ul><li>...no matter WHERE its defined
  50. 50. ...and no matter WHAT format its defined in </li></ul></ul><ul><li>Flexible IoC container + dynamic Python = High Value </li></ul>
  51. 51. <ul>Pure Python IoC </ul><ul><li>@Object-based configuration </li></ul><ul>class MovieBasedConfig(PythonConfig): </ul><ul><ul><ul><li>def __init__(self): </li></ul></ul></ul><ul><ul><ul><ul><li>super(MovieBasedConfig, self).__init__()‏ </li></ul></ul></ul></ul><ul><ul><ul><li>@Object(scope.PROTOTYPE)‏
  52. 52. def MovieLister(self): </li></ul></ul></ul><ul><ul><ul><ul><li>lister = MovieLister()‏
  53. 53. lister.finder = self.MovieFinder()‏
  54. 54. lister.description = self.SingletonString()‏
  55. 55. return lister </li></ul></ul></ul></ul><ul><ul><ul><li>@Object(scope.SINGLETON)‏
  56. 56. def MovieFinder(self): </li></ul></ul></ul><ul><ul><ul><ul><li>return ColonMovieFinder(filename=&quot;support/movies1.txt&quot;)‏ </li></ul></ul></ul></ul>
  57. 57. <ul>Compare with Spring's IoC </ul><ul><li>Similar concepts found in Spring </li></ul><ul><ul><li>Java = beans, Python = objects
  58. 58. @Object is like @Bean
  59. 59. Current scopes: SINGLETON and PROTOTYPE
  60. 60. FUTURE: Lazy initialization, auto-wiring </li></ul></ul><ul><li>Newer concepts not yet found in Spring </li></ul><ul><ul><li>One-and-only-one container type
  61. 61. FUTURE: Fluent API (DSL) configuration </li></ul></ul>
  62. 62. <ul>Question </ul><ul><li>What database problem does Python have? </li></ul>
  63. 63. <ul>Answer </ul><ul><li>The Magic 8 says: “Same problem Java JDBC has!” </li></ul>
  64. 64. <ul>Python's database issue </ul><ul><li>For every query: </li></ul><ul><li>Only difference between every query is SQL and row conversion </li></ul><ul><ul><ul><li>// open connection to database
  65. 65. // create cursor
  66. 66. // execute SQL query
  67. 67. // for eachRow in resultSet </li></ul></ul></ul><ul><ul><ul><ul><li>// convert row into an object </li></ul></ul></ul></ul><ul><ul><ul><li>// close cursor
  68. 68. // close connection </li></ul></ul></ul>
  69. 69. <ul>Why create DatabaseTemplate? </ul><ul><li>Spring's JdbcTemplate helped me write database queries fast in Java
  70. 70. Python apps have the same problem and need the same leverage
  71. 71. DatabaseTemplate should be reason enough for potential users to embrace Spring Python </li></ul>
  72. 72. <ul>ORMs and DatabaseTemplate </ul><ul><li>They provide quick way to persist objects.
  73. 73. But sometimes they are tricky for complex queries. What if... </li><ul><li>You need left outer joins that lack foreign key meta-data
  74. 74. You actually know what a left outer join is and don't need “help”
  75. 75. You are porting from ORM to another
  76. 76. You have a DBA team that can optimize your queries </li></ul></ul>
  77. 77. <ul>How to code a query </ul><ul><li>Piece of PetClinic: </li></ul><ul><li>Use binding variables (?) to avoid SQL injection attacks
  78. 78. Each row of results is passed to callback
  79. 79. Notice lack of cursor management? </li></ul><ul><ul><ul><li>return databaseTemplate.query(&quot;&quot;&quot; </li></ul></ul></ul><ul><ul><ul><ul><li>SELECT id, first_name, last_name, address, city, telephone
  80. 80. FROM owners
  81. 81. WHERE upper(last_name) like ?&quot;&quot;&quot;,
  82. 82. (&quot;%&quot; + lastName.upper() + &quot;%&quot;,),
  83. 83. OwnerRowMapper())‏ </li></ul></ul></ul></ul>
  84. 84. <ul>Immediate payoff </ul><ul><li>Benefits: </li></ul><ul><ul><li>No cursors to manage
  85. 85. No ugly try/except blocks
  86. 86. Focus is on business logic
  87. 87. Query will work with any RDBMS* </li><ul><li>MySQL, Sqlite, PostGreSQL, Oracle </li></ul></ul></ul><ul><ul><ul><li>(*Okay, DB vendors can support different forms of binding variables, but we are ready for that!)‏ </li></ul></ul></ul>
  88. 88. <ul>How to code a row mapper </ul><ul><li>The other side: </li></ul><ul><li>Very useful when you have to code a lot of Owner-based queries </li></ul><ul><ul><li>class OwnerMapper(RowMapper): </li></ul></ul><ul><ul><ul><li>def map_row(self, row): </li></ul></ul></ul><ul><ul><ul><ul><li>owner = Owner()‏
  89. 89. owner.id = row[0]
  90. 90. owner.firstName = row[1]
  91. 91. owner.lastName = row[2]
  92. 92. owner.address = row[3]
  93. 93. owner.city = row[4]
  94. 94. owner.telephone = row[5]
  95. 95. return owner </li></ul></ul></ul></ul>
  96. 96. <ul>Question </ul><ul><li>Have you ever had to deal with transactions? </li></ul>
  97. 97. <ul>Transactions power the enterprise </ul><ul><li>Database calls are valuable for any app, small or large
  98. 98. Transactions power enterprise solutions
  99. 99. Coding transactions is one of the first demands for enterprise apps </li></ul>
  100. 100. <ul>How to code transactions </ul><ul><li>Spring Python makes it easy to programmatically code transactions </li></ul><ul><ul><li>tx_mgr = ConnectionFactoryTransactionManager(factory)‏
  101. 101. tx_template = TransactionTemplate(tx_mgr)‏
  102. 102. dt = DatabaseTemplate(factory)‏
  103. 103. class txDefinition(TransactionCallback): </li></ul></ul><ul><ul><ul><li>def do_in_transaction(s, status): </li></ul></ul></ul><ul><ul><ul><ul><li>dt.execute(&quot;INSERT INTO animal (name) VALUES (?)&quot;,('black mamba',))‏
  104. 104. dt.execute(&quot;INSERT INTO animal (name) VALUES (?)&quot;,('copperhead',))‏
  105. 105. results = dt.queryForObject(&quot;””
  106. 106. SELECT name
  107. 107. FROM animal
  108. 108. WHERE name like 'c%'&quot;, required_type=types.StringType)‏
  109. 109. return results </li></ul></ul></ul></ul><ul><ul><li>print tx_template.execute(txDefinition())‏
  110. 110. >>> &quot;copperhead&quot; </li></ul></ul>
  111. 111. <ul>Declarative transactions are key </ul><ul><li>TransactionTemplate is useful for a handful of transactions
  112. 112. However, marking business methods with @transactional catapults you into the enterprise
  113. 113. Decouples business logic from the database </li></ul>
  114. 114. <ul>How to declare transactions </ul><ul><ul><li>class TransactionalBank(object):
  115. 115. def __init__(self, factory):
  116. 116. self.dt = DatabaseTemplate(factory)‏
  117. 117. @transactional([&quot;PROPAGATION_REQUIRED&quot;])‏
  118. 118. def deposit(self, amount, account_num):
  119. 119. self.dt.execute(&quot;UPDATE account SET balance = balance + ?
  120. 120. WHERE account_num = ?&quot;, (amount, account_num))‏
  121. 121. @transactional([&quot;PROPAGATION_REQUIRED&quot;])‏
  122. 122. def withdraw(self, amount, account_num):
  123. 123. self.dt.execute(&quot;UPDATE account SET balance = balance - ?
  124. 124. WHERE account_num = ?&quot;, (amount, account_num))‏
  125. 125. return amount
  126. 126. @transactional([&quot;PROPAGATION_REQUIRED&quot;])‏
  127. 127. def transfer(self, amount, from_account_num, to_account_num):
  128. 128. self.withdraw(amount, from_account_num)‏
  129. 129. self.deposit(amount, to_account_num)‏ </li></ul></ul>
  130. 130. <ul>Code is clean and easy to read </ul><ul><li>Declarative transactions move configuration to a central location
  131. 131. Your logic is clean, concise, and clear to its purpose
  132. 132. Enterprise apps tend to get HUGE, so maintainable code is paramount to success
  133. 133. Spring Python's declarative transactions are EXACTLY what you need
  134. 134. Spring Python 1.1 shows you the pros and cons of programmatic vs. declarative vs. AOP-based transactions. </li></ul>
  135. 135. <ul>Question </ul><ul><li>At what stage do developers code security into their apps? </li></ul>
  136. 136. <ul>Answer </ul><ul><li>HINT: Its usually not the first thing on your mind </li></ul>
  137. 137. <ul>Security done right is hard </ul><ul><li>Security is a big flaw in modern web apps
  138. 138. Security is typically done last and thus, often rushed
  139. 139. Rushed implementation = WRONG solution
  140. 140. Spring Python's security is the RIGHT solution </li></ul>
  141. 141. <ul>Authentication made easy </ul><ul><li>Authenticating a user is EASY
  142. 142. Uses AOP so your APIs don't change
  143. 143. Familiar with Spring Security? We borrowed their concepts.
  144. 144. Makes Spring Python powerful! </li></ul><ul><ul><li>TODAY: In-memory (for testing), database, LDAP
  145. 145. FUTURE: X.509, OpenID, OpenSSO, Basic HTTP, 2-factor, anything! </li></ul></ul>
  146. 146. <ul>Authorization also easy </ul><ul><li>Authorizing users is also easy
  147. 147. Spring Python is just as powerful
  148. 148. TODAY: </li></ul><ul><ul><li>Role-based and/or Label-based voters
  149. 149. + Affirmative- or Unanimous- or Consensus-based policies
  150. 150. = Powerful, flexible, elegant configuration </li></ul></ul><ul><li>FUTURE: </li></ul><ul><ul><li>read-write-execute ACL voters for domain object security
  151. 151. Anything the community needs! </li></ul></ul>
  152. 152. <ul>Question </ul><ul><li>What technology makes it easy to layer on services without changing APIs? </li></ul>
  153. 153. <ul>Answer </ul><ul><li>Survey says: </li></ul><ul>“ Aspect Oriented Programming” </ul>
  154. 154. <ul>Spring makes AOP easy </ul><ul><li>Spring AOP = easy AOP for Java
  155. 155. Spring Python AOP = easy AOP for Python
  156. 156. Allows enterprise-style services to be easily built around your objects </li></ul><ul><ul><li>Security, transactions, auditing, tracing, performance analysis </li></ul></ul><ul><li>Many parts of Spring Python ride on AOP </li></ul>
  157. 157. <ul>AOP is part of the Spring triangle </ul><ul>Simple Object </ul><ul>Simple Object </ul><ul>Dependency Injection </ul><ul>AOP </ul><ul>Portable Service Abstractions </ul>
  158. 158. <ul>AOP, easy as 1-2-3 </ul><ul><ul><li>class SampleService:
  159. 159. def method(self, data):
  160. 160. return &quot;You sent me '%s'&quot; % data </li></ul></ul><ul><ul><li>service = SampleService()‏
  161. 161. print service.method(&quot;something&quot;)‏
  162. 162. >>> &quot;You sent me 'something'&quot; </li></ul></ul><ul><ul><li>class WrappingSvc(MethodInterceptor):
  163. 163. def invoke(self, invocation):
  164. 164. return &quot;<Wrapped>&quot; + invocation.proceed() + &quot;</Wrapped>&quot; </li></ul></ul><ul><ul><li>service = ProxyFactoryObject(target = SampleService(), interceptors = [WrappingSvc()])‏
  165. 165. print service.method(&quot;something&quot;)‏
  166. 166. >>> &quot;<Wrapped>You sent me 'something'</Wrapped>&quot; </li></ul></ul>
  167. 167. <ul>Question </ul><ul><li>What can you do to make apps redundant and support more clients? </li></ul>
  168. 168. <ul>Answer </ul><ul><li>The answer behind door #3 is: </li></ul><ul>“ Spread your app across multiple nodes” </ul>
  169. 169. <ul>Remoting links things together </ul><ul><li>Remoting is the building block for distributed systems
  170. 170. It allows you to split up apps that need more resources
  171. 171. Horizontal scaling allows you to grow your enterprise
  172. 172. Spring Python allows you to easily supply and consume remote services </li></ul>
  173. 173. <ul>Pyro today, REST & WS tomorrow </ul><ul><li>Today: </li></ul><ul><ul><li>Pyro (Python remote objects) – pure python RPC library
  174. 174. Hessian – interoperable protocol
  175. 175. JMS – link Python-to-Python or Python-to-Java with WebshereMQ </li></ul></ul><ul><li>Tomorrow: </li></ul><ul><ul><li>RESTful web services
  176. 176. COMET-enabled web apps
  177. 177. Twitter
  178. 178. Any web service, or other useful remoting protocol
  179. 179. Other JMS providers </li></ul></ul>
  180. 180. <ul>Agenda </ul><ul><li>History
  181. 181. Technology </li></ul><ul><ul><li>IoC container
  182. 182. Database template
  183. 183. Transactions
  184. 184. Security
  185. 185. AOP
  186. 186. Remoting </li></ul></ul><ul><li>Status </li></ul><ul><ul><li>Current
  187. 187. Future of the project </li></ul></ul>
  188. 188. <ul>Top quality, production-ready </ul><ul><li>Just released 1.1.0.FINAL. Starting 1.2. </li></ul><ul><ul><li>Has ALL key features needed for development </li></ul></ul><ul><li>Top quality </li></ul><ul><ul><li>Tied in to CI: nightly builds and trunk commits
  189. 189. Built from Day 1 using TDD => Code coverage at 85% </li></ul></ul><ul><li>Powerful integration </li></ul><ul><ul><li>CherryPy, Pyro, Hessian, MySQL, PostGreSQL, Sqlite, Oracle </li></ul></ul><ul><li>Documentation is up-to-date and useful </li></ul>
  190. 190. <ul>Community support is important </ul><ul><li>Solutions </li></ul><ul><ul><li>What solutions do python users need?
  191. 191. What 3 rd party libraries can be enhanced or leveraged to provide integrated solutions? </li></ul></ul><ul><li>Community </li></ul><ul><ul><li>Striving to answer any/all questions posted to the forums
  192. 192. Provide fast support to email distribution list
  193. 193. Grow the community of users </li></ul></ul>
  194. 194. <ul>Spring Python has a strong future </ul><ul><li>Quality is always #1 priority
  195. 195. Integrating with top-used tools is important </li></ul><ul><ul><li>Django, Turbogears, Zope/Plone, Paste, Google App Engine, SpringSource Tool Suite, Jython, IronPython </li></ul></ul><ul><li>Books, podcasts, slide shows, video tutorials, anything to support the community </li></ul>
  196. 196. <ul>Spring + Python = powerful solutions </ul><ul><li>Spring Python provides powerful, dynamic, and easy-to-maintain enterprise solutions </li></ul>
  197. 197. <ul>Useful project links </ul><ul><li>Web site: http://springpython.webfactional.com
  198. 198. Book: http://springpythonbook.com
  199. 199. Blog: http://blog.springpython.webfactional.com
  200. 200. Community forum: http://forum.springframework.org
  201. 201. Source code: https://src.springframework.org/svn/se-springpython-py/
  202. 202. Bug tracking: http://jira.springframework.org/browse/SESPRINGPYTHONPY
  203. 203. Mailing list: http://lists.springsource.com/listmanager/listinfo/springpython-users
  204. 204. CI: http://build.springframework.org/browse/EXT-PYSNAPSHOT
  205. 205. Fisheye: https://fisheye.springframework.org/browse/se-springpython-py </li></ul>
  206. 206. <ul>Thank you for your attention </ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×