Intro to Boto (and gevent, )http://www.gevent.org/ Presented 2011-07-01.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

The upper-left corner of a graphics window has the location of: A.0,0 B.200,0 C.0,200 D.200,200.
Automated Web Performance Testing Before 5pm
PHP Form and File Handling
8/26/98IPP IETF1 IPP Scheme –Help users distinguish IPP objects from other web objects. –Users will always see ipp:// as URL format for IPP Printers and.
Supporting Persistent Objects In Python Jeremy Hylton
More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld.
PHP File Upload ISYS 475.
LiNC Developer Meetup Welcome!. Our job is to make your life easier APIs Tools and workflow Documentation Stay in touch: developers.lithium.com Join the.
Overview of Twitter API Nathan Liu. Twitter API Essentials Twitter API is a Representational State Transfer(REST) style web services exposed over HTTP(S).
Struts Portlet Adding an Action Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without.
JBASE jRCS.
AutoTweetNG Free, PRO, and Joocial Publishing to Google+ Profiles and Pages Presentation based on Joomla 3 and AutoTweetNG
Building a Web Crawler in Python Frank McCown Harding University Spring 2013 This work is licensed under a Creative Commons Attribution-NonCommercial-
Gevent network library Denis Bilenko gevent.org. Problem statement from urllib2 import urlopen response = urlopen(' body = response.read()
Tornado Web and MongoDB An Introduction to AsyncMongo MongoBoston John C. Zablocki Development Manager, HealthcareSource Organizer, Beantown.
건전지로 달리는 쟝고 세미나. 정재성 Django Web Framework CGI.
Presenter: James Huang Date: Sept. 29,  HTTP and WWW  Bottle Web Framework  Request Routing  Sending Static Files  Handling HTML  HTTP Errors.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 28 Classes and Methods 6/17/09 Python Mini-Course: Lesson 28 1.
Kit Chan ATS Lua Plugin Kit Chan Hi, My name is kit.
Attributes of SharePoint Migration  Quickly Migrate bulk SharePoint offline or Online database in other SharePoint or Office365.  Transfer Multiple.
Drop in replacement of MySQL. Agenda MySQL branch GPL licence Maria storage engine Virtual columns FederatedX storage engine PBXT storage engine XtraDB.
Using Evernote and Google Docs in your web or mobile application (and potentially Dropbox and Skydrive) By Peter Messenger Senior Developer – Triple Point.
Introduction to Computing Using Python CSC Winter 2013 Week 8: WWW and Search  World Wide Web  Python Modules for WWW  Web Crawling  Thursday:
Amazon S3 – An SOA By: Minam Ulhaq.
Ruby (on Rails) CSE 190M, Spring 2009 Week 3. Web Programming in Ruby Ruby can be used to write dynamic web pages Similar to PHP, chunks of Ruby begins.
A Crash Course Python. Python? Isn’t that a snake? Yes, but it is also a...
Adv. UNIX:Perl/81 Advanced UNIX v Objectives of these slides: –introduce Perl (version ) –mostly based on Chapter 1, Learning Perl
Revealing the Secrets: Source Code Disclosure, Techniques, and Impacts.
Ceph scalable, unified storage files, blocks & objects Tommi Virtanen / DreamHostOpenStack Conference
Lecture 6: Testing/Quality Assurance Damien Markey.
Platform as a Service (PaaS)
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
Finding cacheable areas in your Web Site using Python and Selenium David Elfi Intel.
Web application architecture
CSE 305 Theory of Database Tutorial on Connecting with Sybase from Java program and Developing GUI Jalal Mahmud, TA, CSE 305.
November 13, 2008 Ohio Information Security Forum Attack Surface of Web Applications James Walden Northern Kentucky University
ITIS 1210 Introduction to Web-Based Information Systems Chapter 23 How Web Host Servers Work.
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
H3D API Training  Part 3.1: Python – Quick overview.
Universiti Utara Malaysia Chapter 3 Introduction to ASP.NET 3.5.
JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.
AG Retreat 2006 – Hands-On Session Developing Shared Applications Susanne Lefvert University of Chicago.
Shell Scripting AFNOG IX Rabat, Morocco May 2008.
Concurrency, Parallelism, Events, Asynchronicity, Oh My threads, processes, queues & workers, multiprocessing, gevent, twisted, yo momma SoCal Piggies.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Dynamic Architectures (Component Reconfiguration) with Fractal.
Python iterators and generators. Iterators and generators  Python makes good use of iterators  And has a special kind of generator function that is.
CIT 590 Intro to Programming Files etc. Announcements From HW5 onwards (HW5, HW6,…) You can work alone. You can pick your own partner. You can also stick.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
Saving State on the WWW. The Issue  Connections on the WWW are stateless  Every time a link is followed is like the first time to the server — it has.
Dynamic Flash Images: Increased Functionality and Copy Protection for Online Images Jason W. Nadal.
1 © 2000, Cisco Systems, Inc. Understanding URD and IGMP v3lite 9/2000.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Data Collection and Web Crawling. Overview Data intensive applications are likely to powered by some databases. How do you get the data in your database?
ICM – API Server & Forms Gary Ratcliffe.
First Indico Workshop HTTP API Adrian Mönnich May 2013 CERN.
CIT 590 Intro to Programming Files etc. Agenda Files Try catch except A module to read html off a remote website (only works sometimes)
Dictionaries and File I/O George Mason University.
This is a test Webpage Wow, I’m writing my first webpage.
CIT 590 Intro to Programming Lecture 6. Vote in the doodle poll so we can use some fancy algorithm to pair you up You.
GETTING STARTED WITH AWS AND PYTHON. OUTLINE  Intro to Boto  Installation and configuration  Working with AWS S3 using Bot  Working with AWS SQS using.
Introduction to gathering and analyzing data via APIs Gus Cavanaugh
PHP / MySQL Introduction
DotnetConf 11/17/ :06 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE.
Understanding URD and IGMP v3lite 9/2000
CS/COE 1520 Jarrett Billingsley
DIBBs Brown Dog Tutorial Setup
Presentation transcript:

Intro to Boto (and gevent, ) Presented

What is Boto The Python client library for interacting with AWS APIs. Plural. Tutorial at API reference at This presentation is no substitute for those.

Basic usage >>> import boto.s3 >>> from boto.s3.connection import S3Connection >>> conn = S3Connection('ACCESSKEY', 'SECRET') >>> bucket = conn.create_bucket('mybucket') >>> key = conn.new_key('foo') >>> key.set_contents_from_string('bar')

Buckets and keys bucket = connection.get_bucket(name) bucket = connection.get_bucket(name, validate=False) bucket = connection.create_bucket(name) key = bucket.get_key(name) key = bucket.new_key(name)

~/.boto can make interactive use nicer [Credentials] aws_access_key_id =... aws_secret_access_key =... chmod go= ~/.boto environment is always public, get rid of bad habits >>> from boto.s3.connection import S3Connection >>> conn = S3Connection()

RGW needs special stuff >>> conn = boto.s3.connection.S3Connection(... host='localhost',... port=7280,... is_secure=False,... calling_format=... boto.s3.connection.OrdinaryCallingFormat(),... ) For an example of how to store this in ~/.boto: (should submit upstream...)

640kB should be enough for everyone # store in RAM key.set_contents_from_string(s) s = key.get_contents_as_string() # store in a file key.set_contents_from_filename('/path/to/file.ext') path = os.path.join(tmpdir, 'foo') key.get_contents_to_filename(path)

Temp files don't need names path = os.path.join(tmpdir, 'foo') key.get_contents_to_filename(path) with file(path) as f: firstline = f.readline() os.unlink(path) Better: with tempfile.SpooledTemporaryFile() as f: key.get_contents_to_file(f) f.seek(0) firstline = f.readline() try:... finally: try: os.unlink(path) except OSError as e: if e.errno == errno.ENOENT: pass else: raise

Generate content dynamically (quack like a duck) class CastleOfAaaaaargh(object): def __init__(self, size): self.size = size self.offset = 0 def seek(self, offset): self.offset = offset def tell(self): return self.offset def read(self, size=-1): if size < 0: size = self.size - self.offset size = min(size, self.size - self.offset) self.offset += size return size*'A'

Many hands make light work greenlets, not threads; lightweight, single core schedule at IO or sleep >>> from gevent import monkey >>> monkey.patch_all() >>> import gevent >>> g = gevent.spawn(sum, [1, 2, 3]) >>> g.get() 6 >>> sum([1,2,3]) 6

Group/Pool for lots of similar tasks from gevent import monkey; monkey.patch_all() import gevent.pool def plus((a, b)): return a+b group = gevent.pool.Group() print group.map( plus, ((42, x) for x in xrange(100)), ) [42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141]

Group/Pool for lots of similar tasks from gevent import monkey; monkey.patch_all() import gevent.pool import time def sorter(n): time.sleep(n/10.0) return n group = gevent.pool.Group() gen = group.imap_unordered(sorter, xrange(9, 0, -1)) for result in gen: print result

Write objects in parallel... and if that doesn't make it go fast enough, do multipart uploads!

Questions? Thank you