whats-that-code


Namewhats-that-code JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/matthewdeanmartin/whats_that_code
SummaryGuess programming language from a string or file.
upload_time2023-05-28 20:38:29
maintainer
docs_urlNone
authorMatthew Martin
requires_python>=3.6,<4.0
licenseMIT
keywords language detection programming language detection
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.

Badges
------
[![Libraries.io SourceRank](https://img.shields.io/librariesio/sourcerank/pypi/whats_that_code?longCache=true&style=flat-square)](https://libraries.io/github/matthewdeanmartin/whats_that_code/sourcerank)

[![Downloads](https://static.pepy.tech/badge/whats-that-code/month)](https://pepy.tech/project/whats-that-code)


[![CodeFactor](https://www.codefactor.io/repository/github/matthewdeanmartin/whats_that_code/badge)](https://www.codefactor.io/repository/github/matthewdeanmartin/whats_that_code)

## Usage
```python
from whats_that_code.election import guess_language_all_methods
code = "def yo():\n   print('hello')"
result = guess_language_all_methods(code, file_name="yo.py")
assert result == ["python"]
```

## How it Works
1) Inspects file extension if available.
2) Inspects shebang
3) Looks for keywords
4) Counts regexes for common patterns
5) Attemps to parse python, json, yaml
6) 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](https://github.com/matthewdeanmartin/so_pip) a StackOverflow code
extraction tool I wrote.

## Docs
- [TODO](https://github.com/matthewdeanmartin/whats_that_code/tree/main/docs/TODO.md)
- [LICENSE](https://github.com/matthewdeanmartin/whats_that_code/tree/main/LICENSE)
- [Prior Art](https://github.com/matthewdeanmartin/whats_that_code/tree/main/docs/prior_art.md) Every similar project/tool, including defunct
- [ChangeLog](https://github.com/matthewdeanmartin/whats_that_code/tree/main/docs/CHANGES.md)

## Notable Similar Tools
- [Guesslang](https://pypi.org/project/guesslang/) - python and tensorflow driven solution. Reasonable results but
slow startup and not pure python.
- [pygments](https://pygments.org/docs/api/#pygments.lexers.guess_lexer) pure python, but sometimes lousy identification
rates.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/matthewdeanmartin/whats_that_code",
    "name": "whats-that-code",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6,<4.0",
    "maintainer_email": "",
    "keywords": "language detection,programming language detection",
    "author": "Matthew Martin",
    "author_email": "matthewdeanmartin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/17/43/76d1f51a889e321114f85830cc7b9f4a7e60f8bb35d535da07040ba67c16/whats_that_code-0.2.0.tar.gz",
    "platform": null,
    "description": "# whats_that_code\nThis is a programming language detection library.\n\nIt will detect programming language of source in pure python from an ensemble of classifiers.\nUse this when a quick and dirty first approximation is good enough.\nwhats_that_code can currently identify 60%+ of samples without knowing the extension or tag.\n\nI created this because I wanted\n- a pure python programming language detector\n- no machine learning dependencies\n\nTested on python 3.6 through 3.9.\n\nBadges\n------\n[![Libraries.io SourceRank](https://img.shields.io/librariesio/sourcerank/pypi/whats_that_code?longCache=true&style=flat-square)](https://libraries.io/github/matthewdeanmartin/whats_that_code/sourcerank)\n\n[![Downloads](https://static.pepy.tech/badge/whats-that-code/month)](https://pepy.tech/project/whats-that-code)\n\n\n[![CodeFactor](https://www.codefactor.io/repository/github/matthewdeanmartin/whats_that_code/badge)](https://www.codefactor.io/repository/github/matthewdeanmartin/whats_that_code)\n\n## Usage\n```python\nfrom whats_that_code.election import guess_language_all_methods\ncode = \"def yo():\\n   print('hello')\"\nresult = guess_language_all_methods(code, file_name=\"yo.py\")\nassert result == [\"python\"]\n```\n\n## How it Works\n1) Inspects file extension if available.\n2) Inspects shebang\n3) Looks for keywords\n4) Counts regexes for common patterns\n5) Attemps to parse python, json, yaml\n6) Inspects tags if available.\n\nEach is imperfect and can error. The classifier then combines the results of each using a voting algorithm\n\nThis works best if you only use it for fallback, e.g. classifying code that can't already be classified by extension or tag,\nor when tag is ambiguous.\n\nIt was a tool that outgrew being a part of [so_pip](https://github.com/matthewdeanmartin/so_pip) a StackOverflow code\nextraction tool I wrote.\n\n## Docs\n- [TODO](https://github.com/matthewdeanmartin/whats_that_code/tree/main/docs/TODO.md)\n- [LICENSE](https://github.com/matthewdeanmartin/whats_that_code/tree/main/LICENSE)\n- [Prior Art](https://github.com/matthewdeanmartin/whats_that_code/tree/main/docs/prior_art.md) Every similar project/tool, including defunct\n- [ChangeLog](https://github.com/matthewdeanmartin/whats_that_code/tree/main/docs/CHANGES.md)\n\n## Notable Similar Tools\n- [Guesslang](https://pypi.org/project/guesslang/) - python and tensorflow driven solution. Reasonable results but\nslow startup and not pure python.\n- [pygments](https://pygments.org/docs/api/#pygments.lexers.guess_lexer) pure python, but sometimes lousy identification\nrates.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Guess programming language from a string or file.",
    "version": "0.2.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/matthewdeanmartin/whats_that_code/issues",
        "Change Log": "https://github.com/matthewdeanmartin/whats_that_code/blob/main/docs/CHANGES.md",
        "Documentation": "https://github.com/matthewdeanmartin/whats_that_code",
        "Homepage": "https://github.com/matthewdeanmartin/whats_that_code",
        "Repository": "https://github.com/matthewdeanmartin/whats_that_code"
    },
    "split_keywords": [
        "language detection",
        "programming language detection"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ac5b9a127d4179e86d97fb79f44e0417aff04016adbdaed3cfee48004906d82d",
                "md5": "f5e7f97203fccac40d7c38ec81a4122e",
                "sha256": "923fb3d84ad27c265da7ac2b12251a2055c3325c0bd4dae5e527085b99e84273"
            },
            "downloads": -1,
            "filename": "whats_that_code-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f5e7f97203fccac40d7c38ec81a4122e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6,<4.0",
            "size": 73872,
            "upload_time": "2023-05-28T20:38:27",
            "upload_time_iso_8601": "2023-05-28T20:38:27.402951Z",
            "url": "https://files.pythonhosted.org/packages/ac/5b/9a127d4179e86d97fb79f44e0417aff04016adbdaed3cfee48004906d82d/whats_that_code-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "174376d1f51a889e321114f85830cc7b9f4a7e60f8bb35d535da07040ba67c16",
                "md5": "ad59898d427e6c0a7da2d5b9be5492c3",
                "sha256": "938fb2443a6a7eb23ceee20f0c246922f206c7356b542113d3161314f8cdc61d"
            },
            "downloads": -1,
            "filename": "whats_that_code-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ad59898d427e6c0a7da2d5b9be5492c3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6,<4.0",
            "size": 69832,
            "upload_time": "2023-05-28T20:38:29",
            "upload_time_iso_8601": "2023-05-28T20:38:29.066038Z",
            "url": "https://files.pythonhosted.org/packages/17/43/76d1f51a889e321114f85830cc7b9f4a7e60f8bb35d535da07040ba67c16/whats_that_code-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-28 20:38:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "matthewdeanmartin",
    "github_project": "whats_that_code",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "whats-that-code"
}
        
Elapsed time: 0.08499s