searchcode


Namesearchcode JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://searchcode.com
SummaryAn unofficial Python SDK for Searchcode.
upload_time2024-11-20 17:40:44
maintainerNone
docs_urlNone
authorRichard Mwewa
requires_python<4.0,>=3.10
licenseGPL-3.0+ License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center"><img src="https://github.com/user-attachments/assets/d28934e1-a1ab-4b6e-9d12-d64067a65a60"><br>An unofficial Python SDK for <a href="https://searchcode.com">SearchCode</a>.<br><i>Search 75 billion lines of code from 40 million projects</i></p>
<p align="center"></p>
<p align="center">
  <a href="https://github.com/knewkarma-io/knewkarma"><img alt="Code Style" src="https://img.shields.io/badge/code%20style-black-000000?logo=github&link=https%3A%2F%2Fgithub.com%2Frly0nheart%2Fknewkarma"></a>
</p>

## Table Of Contents
* [Code_search](#code_search)
    * [Example (Without Filters)](#example-without-filters)
    * [Example Language Filter (Java and Javascript)](#example-language-filter-java-and-javascript)
    * [Example Source Filter (Bitbucket and CodePlex)](#example-source-filter-bitbucket-and-codeplex)
    * [Example Lines of Code Filter (Between 500 and 1000)](#example-lines-of-code-filter-between-500-and-1000)
    * [Example (JSONP)](#example-jsonp)
    * [Response Attribute Definitions](#response-attribute-definitions)
* [code_result](#code_result)
    * [Example](#example)
* [related_results](#related_results)
    * [Example](#example-1)
    * [Response Attribute Definitions](#response-attribute-definitions-1)
* [About Searchcode](#about-searchcode)
* [Credit](#credit)

***

## code_search

Queries the code index and returns at most 100 results.

> [!TIP]
All filters supported by searchcode are available. These include
`sources`, `languages` and `lines_of_code`. These work in the same way that the main page works; See the examples below for how to use them.

> [!TIP] 
To fetch all results for a given query, keep incrementing the `page` parameter until you get a page with an empty
results list.

> [!IMPORTANT]
If the results list is empty, then this indicates that you have reached the end of the available results.


### Example (Without Filters):

```python
import searchcode as sc

search = sc.code_search(query="test")

for result in search.results:
    print(result)
```

### Example Language Filter (Java and Javascript):

```python
import searchcode as sc

search = sc.code_search(query="test", languages=["Java", "JavaScript"])

for result in search.results:
    print(result.language)
```

### Example Source Filter (Bitbucket and CodePlex):

```python
import searchcode as sc

search = sc.code_search(query="test", sources=["BitBucket", "CodePlex"])

for result in search.results:
    print(result.filename)
```

### Example Lines of Code Filter (Between 500 and 1000):

```python
import searchcode as sc

search = sc.code_search(query="test", lines_of_code=500, lines_of_code2=1000)

for result in search.results:
    print(result.linescount)
```

### Example (JSONP):

```python
import searchcode as sc

search = sc.code_search(query="soup", page=1, callback="myCallback")

for result in search.results:
    print(result)
```

### Response Attribute Definitions

| Attribute            | Description                                                                                                                                                                                               |
|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **searchterm**       | Search term supplied to the API through the use of the `q` parameter.                                                                                                                                     |
| **query**            | Identical to `searchterm` and included for historical reasons to maintain backward compatibility.                                                                                                         |
| **matchterm**        | Identical to `searchterm` and included for historical reasons to maintain backward compatibility.                                                                                                         |
| **page**             | ID of the current page that the query has returned. This is a zero-based index.                                                                                                                           |
| **nextpage**         | ID of the offset of the next page. Always set to the current page + 1, even if you have reached the end of the results. This is a zero-based index.                                                       |
| **previouspage**     | ID of the offset of the previous page. If no previous page is available, it will be set to `null`. This is a zero-based index.                                                                            |
| **total**            | The total number of results that match the `searchterm` in the index. Note that this value is approximate. It becomes more accurate as you go deeper into the results or use more filters.                |
| **language_filters** | Returns an array containing languages that exist in the result set.                                                                                                                                       |
| **id**               | Unique ID for this language used by searchcode, which can be used in other API calls.                                                                                                                     |
| **count**            | Total number of results that are written in this language.                                                                                                                                                |
| **language**         | The name of this language.                                                                                                                                                                                |
| **source_filters**   | Returns an array containing sources that exist in the result set.                                                                                                                                         |
| **id**               | Unique ID for this source used by searchcode, which can be used in other API calls.                                                                                                                       |
| **count**            | Total number of results that belong to this source.                                                                                                                                                       |
| **source**           | The name of this source.                                                                                                                                                                                  |
| **results**          | Returns an array containing the matching code results.                                                                                                                                                    |
| **id**               | Unique ID for this code result used by searchcode, which can be used in other API calls.                                                                                                                  |
| **filename**         | The filename for this file.                                                                                                                                                                               |
| **repo**             | HTML link to the location of the repository where this code was found.                                                                                                                                    |
| **linescount**       | Total number of lines in the matching file.                                                                                                                                                               |
| **location**         | Location inside the repository where this file exists.                                                                                                                                                    |
| **name**             | Name of the repository that this file belongs to.                                                                                                                                                         |
| **language**         | The identified language of this result.                                                                                                                                                                   |
| **url**              | URL to searchcode's location of the file.                                                                                                                                                                 |
| **md5hash**          | Calculated MD5 hash of the file's contents.                                                                                                                                                               |
| **lines**            | Contains line numbers and lines which match the `searchterm`. Lines immediately before and after the match are included. If only the filename matches, up to the first 15 lines of the file are returned. |

## code_result

Returns the raw data from a code file given the code id which can be found as the id in a code search result.

### Example:

```python
import searchcode as sc

result = sc.code_result(id=4061576)
print(result)
```

> Returns raw data from the code file.

## related_results

Returns an array of results given a searchcode unique code id which are considered to be duplicates. 

> [!IMPORTANT]
The matching is
slightly fuzzy allowing so that small differences between files are ignored.

### Example:

```python
import searchcode as sc

related = sc.related_results(id=4061576)
print(related)
```

### Response Attribute Definitions

| Attribute      | Description                                                                              |
|----------------|------------------------------------------------------------------------------------------|
| **reponame**   | Name of the repository which this related result belongs to.                             |
| **source**     | The source which this code result comes from.                                            |
| **sourceurl**  | URL to the repository this result belongs to.                                            |
| **md5hash**    | Calculated MD5 hash of the file's contents.                                              |
| **location**   | Location inside the repository where this file exists.                                   |
| **language**   | Name of the language which this file is identified to be.                                |
| **linescount** | Total number of lines in this file.                                                      |
| **id**         | Unique ID for this code result used by searchcode, which can be used in other API calls. |
| **filename**   | The filename for this file.                                                              |

## About Searchcode

Read more about searchcode [here](https://searchcode.com/about/)

## Credit

Special thanks to [Ben Boyter](https://boyter.org/about/), developer of [searchcode.com](https://searchcode.com)


            

Raw data

            {
    "_id": null,
    "home_page": "https://searchcode.com",
    "name": "searchcode",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "Richard Mwewa",
    "author_email": "rly0nheart@duck.com",
    "download_url": "https://files.pythonhosted.org/packages/30/04/03847a48b33a7d73f558361646bfb53078a24ce20c2c3fd0c4c74e53a5cd/searchcode-0.1.1.tar.gz",
    "platform": null,
    "description": "<p align=\"center\"><img src=\"https://github.com/user-attachments/assets/d28934e1-a1ab-4b6e-9d12-d64067a65a60\"><br>An unofficial Python SDK for <a href=\"https://searchcode.com\">SearchCode</a>.<br><i>Search 75 billion lines of code from 40 million projects</i></p>\n<p align=\"center\"></p>\n<p align=\"center\">\n  <a href=\"https://github.com/knewkarma-io/knewkarma\"><img alt=\"Code Style\" src=\"https://img.shields.io/badge/code%20style-black-000000?logo=github&link=https%3A%2F%2Fgithub.com%2Frly0nheart%2Fknewkarma\"></a>\n</p>\n\n## Table Of Contents\n* [Code_search](#code_search)\n    * [Example (Without Filters)](#example-without-filters)\n    * [Example Language Filter (Java and Javascript)](#example-language-filter-java-and-javascript)\n    * [Example Source Filter (Bitbucket and CodePlex)](#example-source-filter-bitbucket-and-codeplex)\n    * [Example Lines of Code Filter (Between 500 and 1000)](#example-lines-of-code-filter-between-500-and-1000)\n    * [Example (JSONP)](#example-jsonp)\n    * [Response Attribute Definitions](#response-attribute-definitions)\n* [code_result](#code_result)\n    * [Example](#example)\n* [related_results](#related_results)\n    * [Example](#example-1)\n    * [Response Attribute Definitions](#response-attribute-definitions-1)\n* [About Searchcode](#about-searchcode)\n* [Credit](#credit)\n\n***\n\n## code_search\n\nQueries the code index and returns at most 100 results.\n\n> [!TIP]\nAll filters supported by searchcode are available. These include\n`sources`, `languages` and `lines_of_code`. These work in the same way that the main page works; See the examples below for how to use them.\n\n> [!TIP] \nTo fetch all results for a given query, keep incrementing the `page` parameter until you get a page with an empty\nresults list.\n\n> [!IMPORTANT]\nIf the results list is empty, then this indicates that you have reached the end of the available results.\n\n\n### Example (Without Filters):\n\n```python\nimport searchcode as sc\n\nsearch = sc.code_search(query=\"test\")\n\nfor result in search.results:\n    print(result)\n```\n\n### Example Language Filter (Java and Javascript):\n\n```python\nimport searchcode as sc\n\nsearch = sc.code_search(query=\"test\", languages=[\"Java\", \"JavaScript\"])\n\nfor result in search.results:\n    print(result.language)\n```\n\n### Example Source Filter (Bitbucket and CodePlex):\n\n```python\nimport searchcode as sc\n\nsearch = sc.code_search(query=\"test\", sources=[\"BitBucket\", \"CodePlex\"])\n\nfor result in search.results:\n    print(result.filename)\n```\n\n### Example Lines of Code Filter (Between 500 and 1000):\n\n```python\nimport searchcode as sc\n\nsearch = sc.code_search(query=\"test\", lines_of_code=500, lines_of_code2=1000)\n\nfor result in search.results:\n    print(result.linescount)\n```\n\n### Example (JSONP):\n\n```python\nimport searchcode as sc\n\nsearch = sc.code_search(query=\"soup\", page=1, callback=\"myCallback\")\n\nfor result in search.results:\n    print(result)\n```\n\n### Response Attribute Definitions\n\n| Attribute            | Description                                                                                                                                                                                               |\n|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **searchterm**       | Search term supplied to the API through the use of the `q` parameter.                                                                                                                                     |\n| **query**            | Identical to `searchterm` and included for historical reasons to maintain backward compatibility.                                                                                                         |\n| **matchterm**        | Identical to `searchterm` and included for historical reasons to maintain backward compatibility.                                                                                                         |\n| **page**             | ID of the current page that the query has returned. This is a zero-based index.                                                                                                                           |\n| **nextpage**         | ID of the offset of the next page. Always set to the current page + 1, even if you have reached the end of the results. This is a zero-based index.                                                       |\n| **previouspage**     | ID of the offset of the previous page. If no previous page is available, it will be set to `null`. This is a zero-based index.                                                                            |\n| **total**            | The total number of results that match the `searchterm` in the index. Note that this value is approximate. It becomes more accurate as you go deeper into the results or use more filters.                |\n| **language_filters** | Returns an array containing languages that exist in the result set.                                                                                                                                       |\n| **id**               | Unique ID for this language used by searchcode, which can be used in other API calls.                                                                                                                     |\n| **count**            | Total number of results that are written in this language.                                                                                                                                                |\n| **language**         | The name of this language.                                                                                                                                                                                |\n| **source_filters**   | Returns an array containing sources that exist in the result set.                                                                                                                                         |\n| **id**               | Unique ID for this source used by searchcode, which can be used in other API calls.                                                                                                                       |\n| **count**            | Total number of results that belong to this source.                                                                                                                                                       |\n| **source**           | The name of this source.                                                                                                                                                                                  |\n| **results**          | Returns an array containing the matching code results.                                                                                                                                                    |\n| **id**               | Unique ID for this code result used by searchcode, which can be used in other API calls.                                                                                                                  |\n| **filename**         | The filename for this file.                                                                                                                                                                               |\n| **repo**             | HTML link to the location of the repository where this code was found.                                                                                                                                    |\n| **linescount**       | Total number of lines in the matching file.                                                                                                                                                               |\n| **location**         | Location inside the repository where this file exists.                                                                                                                                                    |\n| **name**             | Name of the repository that this file belongs to.                                                                                                                                                         |\n| **language**         | The identified language of this result.                                                                                                                                                                   |\n| **url**              | URL to searchcode's location of the file.                                                                                                                                                                 |\n| **md5hash**          | Calculated MD5 hash of the file's contents.                                                                                                                                                               |\n| **lines**            | Contains line numbers and lines which match the `searchterm`. Lines immediately before and after the match are included. If only the filename matches, up to the first 15 lines of the file are returned. |\n\n## code_result\n\nReturns the raw data from a code file given the code id which can be found as the id in a code search result.\n\n### Example:\n\n```python\nimport searchcode as sc\n\nresult = sc.code_result(id=4061576)\nprint(result)\n```\n\n> Returns raw data from the code file.\n\n## related_results\n\nReturns an array of results given a searchcode unique code id which are considered to be duplicates. \n\n> [!IMPORTANT]\nThe matching is\nslightly fuzzy allowing so that small differences between files are ignored.\n\n### Example:\n\n```python\nimport searchcode as sc\n\nrelated = sc.related_results(id=4061576)\nprint(related)\n```\n\n### Response Attribute Definitions\n\n| Attribute      | Description                                                                              |\n|----------------|------------------------------------------------------------------------------------------|\n| **reponame**   | Name of the repository which this related result belongs to.                             |\n| **source**     | The source which this code result comes from.                                            |\n| **sourceurl**  | URL to the repository this result belongs to.                                            |\n| **md5hash**    | Calculated MD5 hash of the file's contents.                                              |\n| **location**   | Location inside the repository where this file exists.                                   |\n| **language**   | Name of the language which this file is identified to be.                                |\n| **linescount** | Total number of lines in this file.                                                      |\n| **id**         | Unique ID for this code result used by searchcode, which can be used in other API calls. |\n| **filename**   | The filename for this file.                                                              |\n\n## About Searchcode\n\nRead more about searchcode [here](https://searchcode.com/about/)\n\n## Credit\n\nSpecial thanks to [Ben Boyter](https://boyter.org/about/), developer of [searchcode.com](https://searchcode.com)\n\n",
    "bugtrack_url": null,
    "license": "GPL-3.0+ License",
    "summary": "An unofficial Python SDK for Searchcode.",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://searchcode.com",
        "Repository": "https://github.com/rly0nheart/searchcode-sdk"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a1fbea7627b20a8cee7becd92ded858deb939acdc0981bbc60ee81deebb67cc2",
                "md5": "db471ec9eaaa876a75f20248a290a73a",
                "sha256": "bd598571a66c8d06af7a675e46c40ef84d14885ad915920ad944879db35ba404"
            },
            "downloads": -1,
            "filename": "searchcode-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "db471ec9eaaa876a75f20248a290a73a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 23109,
            "upload_time": "2024-11-20T17:40:43",
            "upload_time_iso_8601": "2024-11-20T17:40:43.184676Z",
            "url": "https://files.pythonhosted.org/packages/a1/fb/ea7627b20a8cee7becd92ded858deb939acdc0981bbc60ee81deebb67cc2/searchcode-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "300403847a48b33a7d73f558361646bfb53078a24ce20c2c3fd0c4c74e53a5cd",
                "md5": "30cad1d65c6d2cfa649ce4618c33122a",
                "sha256": "7f48025570fe7f9a74daf1223fce7d7a6034c4e0201fadaddcaf63969b92732a"
            },
            "downloads": -1,
            "filename": "searchcode-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "30cad1d65c6d2cfa649ce4618c33122a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 24168,
            "upload_time": "2024-11-20T17:40:44",
            "upload_time_iso_8601": "2024-11-20T17:40:44.750630Z",
            "url": "https://files.pythonhosted.org/packages/30/04/03847a48b33a7d73f558361646bfb53078a24ce20c2c3fd0c4c74e53a5cd/searchcode-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-20 17:40:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rly0nheart",
    "github_project": "searchcode-sdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "searchcode"
}
        
Elapsed time: 0.44461s