codetype
is a Python library and command-line tool for identifying the language of source code snippets and files. It's fast, simple and accurate. You can test it out here.
See my blog post for more information.
pip install codetype
$ git clone https://github.com/jdkato/codetype.git
$ cd codetype
$ python setup.py install
>>> from codetype import identify
>>> identify('fibs = 0 : 1 : zipWith (+) fibs (tail fibs)')
'Haskell'
>>> identify('from math import fabs')
'Python'
>>> src = """
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}"""
>>> identify(src)
'Java'
>>> identify('/path/to/ruby/file.txt')
'Ruby'
usage: codetype [-h] [--version] [-v] [-m MAX] [-o ONLY [ONLY ...]] file
A source code identification tool.
positional arguments:
file path to unknown source code
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
-v, --verbose use verbose output
-m MAX, --max MAX max number of languages to return
-o ONLY [ONLY ...], --only ONLY [ONLY ...]
test only the specified formats
AppleScript, C#, C++, C, D, Go, Haskell, Java, JavaScript, Julia, Lua, OCaml, Objective-C, Perl, PHP, Python, R, Ruby, Rust, Scala & Swift
$ python run.py dev -t