non standard library


Павел Тысляцкий

virtualenv + pip*


  • независимые окружения**
  • не портит систему
  • не нужно sudo
  • любые версии
  • pypi
  • wheel
  • requirements.txt


* Убрать слайд после перехода на python 3.4

** Есть ньансы при которых окружения являются не абсолютно независимыми

IPython + IPython-NoteBook


  • интерактивная консоль
  • подсветка кода
  • автодополноение
  • дополнительный синтаксис

nose + mock + coverage + PEP8


  • быстрые тесты
  • независимые тесты
  • pep8 код

SH


from sh import *

# print wlan0 interface
print(ifconfig("wlan0"))

# checkout master branch
git.checkout("master")

# print the contents of this directory
print(ls("-l"))

# get the longest line of this file
longest_line = wc(__file__, "-L")

https://github.com/amoffat/sh

DOCOPT


"""Usage: my_program.py [-hso FILE] [--quiet | --verbose] [INPUT ...]

-h --help    show this
-s --sorted  sorted output
-o FILE      specify output file [default: ./test.txt]
--quiet      print less text
--verbose    print more text

"""
from docopt import docopt


if __name__ == '__main__':
    arguments = docopt(__doc__, version='my program 2.0')
    print(arguments)

https://github.com/docopt/docopt

LXML


  • очень быстрый
  • хорош для больших файлов
  • XML
  • HTML


http://lxml.de

PyQuery


>>> from pyquery import PyQuery as pq
>>> from lxml import etree
>>> import urllib
>>> d = pq(url='http://google.com/', opener=lambda url, **kw: urllib.urlopen(url).read())
>>> d("#hello")
[<p#hello.hello>]
>>> p = d("#hello")
>>> print(p.html())
Hello world !
>>> p.html("you know <a href='http://python.org/'>Python</a> rocks")
[<p#hello.hello>]
>>> print(p.html())
you know <a href="http://python.org/">Python</a> rocks
>>> print(p.text())
you know Python rocks

https://github.com/gawel/pyquery

REQUESTS


Requests: HTTP for Humans


>>> r = requests.get('https://api.github.com', auth=('user', 'pass'))

>>>
r.status_code 204
>>>
r.headers['content-type'] 'application/json'
>>>
r.text
...

https://github.com/kennethreitz/requests

ScraPy


class MySpider(CrawlSpider):
    name = 'example.com'
    allowed_domains = ['example.com']
    start_urls = ['http://www.example.com']
    rules = (
        Rule(SgmlLinkExtractor(deny=('item\.php',))),
        Rule(SgmlLinkExtractor(allow=('item\.php',)), callback='parse'),
    )

    def parse(self, response):
        sel = Selector(response)
        item = Item()
        item['id'] = sel.xpath('//td[@id="item"]/text()').re(r'ID: (\d+)')
        item['name'] = sel.xpath('//td[@id="item_name"]/text()').extract()
        return item


http://scrapy.org

pycrypto


не придумывайте велосипед!!!


  • хеш функции
  • шифрование
    • симметричное
    • асимметричное
  • python 2.1+


    https://www.dlitz.net/software/pycrypto/

    Pillow (Pil)


    >>> from PIL import Image
    >>> im = Image.open("lena.ppm")
    
    >>> print(im.format, im.size, im.mode)
    PPM (512, 512) RGB
    

    https://github.com/python-imaging/Pillow

    GIMP


    image = pdb.gimp_file_load('border.xcf', 'border.xcf')
    layer = pdb.gimp_file_load_layer(image, 'content.xcf')

    layer.set_offsets(5, 5)
    image.add_layer(layer, 1)
    merged_layer = image.merge_visible_layers(0)
    image.scale(30, 36)

    pdb.file_png_save2(image,merged_layer,'bi.png','bi.png',0,9,0,0,0,0,0,0,0)
    gimp --no-interface --batch-interpreter python-fu-eval --batch "<PY BODY>" 

    http://www.gimp.org/docs/python

    Tempaltes


    WEB


    GUI


    Administration


    Data



    http://pydata.org

    Persistence


    QUEUES


    и МНОГОЕ ДРУГОЕ...


    • более 40000 пакетов на PyPi
    • более 88000 проектов на GitHub
    • практически на все случаи жизни

    Ссылки

    http://pypi-ranking.info/alltime

    http://pythonhackers.com/open-source

    https://wiki.python.org/moin/UsefulModules



    Вопросы

    pavel.tyslyatsky@gmail.com

    Non Standard Library

    By Pavel Tyslacki

    Non Standard Library

    • 1,072