pyimportcan -- Python imports canonical format filter. It is free software: see the file COPYING for copying conditions. PROBLEM Python allows various different formats of how to make importing of modules and functions: * from foo import bar * from foo import bar, baz * from foo import ( bar, baz ) * from foo import ( baz, bar, ) * from foo import bar, \ baz Everything can be unsorted at any place, thus making the task of checking if import already exists rather hard. Moreover it complicates just adding another import, because you have to find it first and deal with the format it is already written. Everything can use different indentation practices. Everything can be doubled and you won't notice it: from foo import bar [many lines] from foo import ( baz, bar ) Allowing multiple imports on one line leads to possibility of long lines appearing. The whole import sections with various formats just can not be technically sorted with the editor (no way to do "vip:sort" in Vim). Merge conflict in the imports section can be not so trivial to resolve, however in most cases just aggregating them will be enough. If you want to find the code that imports bar from foo, then you can do it with "from foo import bar", but can not with "import (\n" is most cases. You are forced to use special Python-related software to deal with it, but no grep or sed. SOLUTION Use the very convenient simple single format. Single import per line, period. Sorted and only identical ones. With git merge conflict lines removed. This script reads stdin with import-lines and writes canonical representation of them to stdout. For example you can select lines in Vim and just enter ":!pyimportcan.pl".