from pygments.lexers import guess_lexer, guess_lexer_for_filename
guess_lexer("""#!/usr/bin/python
print "Hello World!\"""")
Is there a library that will detect the source code language of a block of code?