Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python Grab Bag - Opinions for the Unopinionated

Python Grab Bag - Opinions for the Unopinionated

PyCon AU 2013 Lightning Talk, Sunday 7 July 2013

davidjb

July 07, 2013
Tweet

More Decks by davidjb

Other Decks in Programming

Transcript

  1. Python Grab Bag: Opinions for the Unopinionated PyCon AU 2013

    David Beitey Slides @ https://speakerdeck.com/davidjb
  2. vars(self) class David: name = 'David Beitey' home = 'Townsville,

    North Queensland' really_really_cold = True position = 'Web integration & development' github = '@davidjb' twitter = '@davidjb_' #Not NZ selling cheese shameless_plug = 'Python NQ Users Group'
  3. Help! I need to do something in Python! • Good

    news: huge number of PyPI packages. • Bad news: huge number of PyPI packages. • So, what to do? Find, learn, and use good tools! • Everyone's time is limited • Here's an intro into a few things I use (and contribute to).
  4. tl;dr pip install dogpile.cache natural fanstatic #Extras, if time permits

    pip install tilestache uWSGI bleach fabric ... Profit from selling 'Fanstatic Natural Dogpile Cache' as band name!
  5. natural - Data to Human • Convert raw values into

    human • Dates, deltas, durations; File times, sizes, throughput; Numbers, ordinals, morse code, in words; and more. >>> import datetime; from natural import data, date, file, number, size, text >>> data.throughput(1024) '1.00 kB/s' >>> date.day(datetime.datetime.now()) 'today' >>> date.duration(datetime.datetime(2013, 1, 1), precision=3) '26 weeks, 5 days, 1 hour ago' >>> file.accessed('/tmp/cheese') '18 hours ago' >>> file.size('/tmp/cheese') '645.00 KB' >>> number.word(30000000000000000000000000000000000000000000000000000000000000000) '3 vigintillion' >>> text.morse('I can haz cheezburger') '.. / -.-. .- -. / .... .- --.. / -.-. .... . . --.. -... ..- .-. --. . .-.' #Perfect for lolcats that speak morse code.
  6. dogpile.cache - Callable Caching • Successor to the 'caching' part

    of Beaker • Decorators, cache regions, customisable expiration times, get-or-create pattern • Backends: Memcached, Redis, anydm, RAM. >>> six, nine = (6, 7) >>> from dogpile.cache import make_region >>> cache = make_region().configure('dogpile.cache.memory') >>> @cache.cache_on_arguments() ... def answer_to_ultimate_question(): ... return six * nine ... >>> print(answer_to_ultimate_question()) #Now cached until expiration 42
  7. fanstatic - Static web resources • Python packaged JS/CSS resources

    • Include in install_requires in setup.py file • Sane versioning, URL generation, bundling, minification and more -- js.* packages (100+). • Integration with any WSGI apps and Python frameworks (Django, Pyramid, Flask, etc) >>> from js.jquery import jquery >>> #Your favourite web framework here >>> def knights_who_say(context, request): >>> #Can be called any time during request handling ... #Resources automatically included on page ... jquery.need() ... return {'v': 'Ekki-Ekki-Ekki-Ekki-PTANG. Zoom-Boing. Z-nourrwringmm.'}
  8. What, you mean I have more time? Stall! • TileStache

    (Lightweight WSGI map tile server) ◦ Load tiles, vectors, GeoJSON - cache everywhere! ◦ Become your own Google Maps with TileMill & map theming with CartoCSS! • uWSGI (application) ◦ Serves everything [Python, Ruby, Java, Perl, Erlang & more] ◦ Protocol 25%+ faster than HTTP (via TCP) ◦ Anything you run now can (probably) be loaded immediately • bleach (sanitise/linkify untrusted HTML) • fabric (SSH streamlining awesomeness)
  9. Check them out • http://natural.rtfd.org • http://dogpilecache.rtfd.org • http://fanstatic.org (not

    a typo) • http://tilestache.org • http://www.mapbox.com/tilemill/ • http://uwsgi-docs.rtfd.org/ • https://pypi.python.org/pypi/bleach • http://fabfile.org Slides @ https://speakerdeck.com/davidjb