GustavePate / perfect_python_script

The perfect python script: A demonstrator and reminder for the most usefull python libraries and best practices

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The Perfect Python Script

Build Status

Based on this reddit post

This is a python script template, and it's a demonstrator and reminder for the most usefull python libraries and best practices

Context

The Hitchhiker’s Guide to Python and Python patterns

This script template aim is to enforce best-pratices use.

Please contribute if you feel it should be better written. Pull Request welcome !!!

This template make use of

Generalities

  • logging
  • Makefile
  • requirement.txt / virtualenv
  • Json configuration / Borg
  • argument parsing: click
  • python 2.7 / 3.4 compatibility

Quality

  • py.test
  • travis ci
  • pep8 compliance check

Pretty

  • colorlog
  • click progress bar

Usefull libraries

  • collections: specifically namedtuples
  • tempfile: always use this to create temporary files
  • pillow: image juggling
  • decimal: you will need it, try this if you dare: print((0.1 + 0.1 + 0.1 - 0.3) == 0)

data

  • csv: always use this to read/write CSV files, don't try and roll your own methods, it'll end in tears
  • sqllite

Todo

  • pandas -- csv loading and quick graphing
  • datetime
  • math -- try and use these functions rather than the global ones, as they're faster when you import them into the global namespace
  • re -- regular expressions
  • requests -- if you need to do any http requests at all, use this
  • string -- I rarely see this used, but it's very handy
  • rename git repo to perfect python script
  • sphinx
  • matplotlib
  • unittest
  • lxml -- always use this for working with XML data
  • BeautifulSoup -- for webscraping and/or parsing potentially malformed HTML
  • os / shutils
  • setuptools
  • redis

## Don't know if it's usefull

  • buildout -- I'd recommend this over virtualenv any day
  • PyYAML -- for working with YAML docs.
  • ujson -- faster than both simplejson and the built-in json modules, handy if you work with lots of/big JSON blobs

See also

About

The perfect python script: A demonstrator and reminder for the most usefull python libraries and best practices

License:MIT License


Languages

Language:Python 98.4%Language:Makefile 0.9%Language:Shell 0.6%