Guess programming language from a string or file.
Project description
whats_that_code
This is a programming language detection library.
It will detect programming language of source in pure python from an ensemble of classifiers. Use this when a quick and dirty first approximation is good enough. whats_that_code can currently identify 60%+ of samples without knowing the extension or tag.
I created this because I wanted
- a pure python programming language detector
- no machine learning dependencies
Tested on python 3.6 through 3.9.
Usage
> code = "def yo():\n print('hello')"
> guess_language_all_methods(code, file_name="yo.py")
["python"]
How it Works
- Inspects file extension if available.
- Inspects shebang
- Looks for keywords
- Counts regexes for common patterns
- Attemps to parse python, json, yaml
- Inspects tags if available.
Each is imperfect and can error. The classifier then combines the results of each using a voting algorithm
This works best if you only use it for fallback, e.g. classifying code that can't already be classified by extension or tag, or when tag is ambiguous.
It was a tool that outgrew being a part of so_pip a StackOverflow code extraction tool I wrote.
Docs
Notable Similar Tools
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file whats_that_code-0.1.6.tar.gz
.
File metadata
- Download URL: whats_that_code-0.1.6.tar.gz
- Upload date:
- Size: 77.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74f6a6965c7a97155002d6968684ade1fd6a00224fca6ea94df8dc14539f13cf |
|
MD5 | be9a8d0a2cd3cfc0684e1272e7bf8690 |
|
BLAKE2b-256 | a4b50b1f04c5b6473ad18235107c7a7b8bcd8dca30555fce718e65ad31ede226 |
File details
Details for the file whats_that_code-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: whats_that_code-0.1.6-py3-none-any.whl
- Upload date:
- Size: 80.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c052e4dbce9be3b1604b68ea309d469d1e38a4580026a6ca6d90821d56d6fb9c |
|
MD5 | 00304dee0800fcd455fa789dc13cb385 |
|
BLAKE2b-256 | d77f38b2ae4108e459b4eff2a7d5363109ce69628540be9000ae8b701084eebf |