Legalese

Disclaimer

The searchcode API is provided "as is" and on an "as-available" basis. All care is taken but there is no warranty provided that the API will be error free or that access will be continuous or uninterrupted.

Liability

In no event will searchcode be liable with to respect to any special, incidental, or consequential damages; the cost of procurement of substitute products or services; or for interruption of use or loss or corruption of data.

Conditions

The only condition of using the searchcode API is to provide a clickable link attributing searchcode as the source. No rate limiting implemented unless abuse is detected. Operate as Bill and Ted would and "Be excellent to each other".

Corporate Usage

Generally speaking corporate usage using the searchcode API is not an issue. However if you are running a company with business critial functions using the API and want to ensure the service is still running next week, contact Ben via bboyte01@gmail.com and we can work some form of commercial licence out.


Code Index

Queries the code index and returns at most 100 results. All filters supported by searchcode are available. These include src (sources), lan (languages) and loc (lines of code). These work in the same way that the main page works. See the examples for how to use these.

If the results list is empty, then this indicates that you have reached the end of the available results. To fetch all results for a given query, keep incrementing 'p' until you get a page with an empty results list. Note you can reach further into the results by setting per_page to 100.

JSON

https://searchcode.com/api/codesearch_I/?q=[searchterm]&p=[page]&per_page[per_page]&lan=[lan]&src=[src]&loc=[loc]&loc2=[loc2]

JSONP

https://searchcode.com/api/jsonp_codesearch_I/?q=[searchterm]&p=[page]&per_page[per_page]&lan=[lan]&src=[src]&loc=[loc]&loc2=[loc2]&callback=[myCallback]

Params

  • q: search term
    The following filters are textual and can be added into query directly
    • Filter by file extention ext:EXTENTION E.g. "gsub ext:erb"
    • Filter by language lang:LANGUAGE E.g. "import lang:python"
    • Filter by repository repo:REPONAME E.g. "float Q_rsqrt repo:quake"
    • Filter by user/repository repo:USERNAME/REPONAME E.g. "batf repo:boyter/batf"
  • p: result page starting at 0 through to 49
  • callback: callback function (JSONP only)
  • per_page: number of results wanted per page max 100
  • lan: allows filtering to languages supplied by return types. Supply multiple to filter to multiple languages.
  • src: allows filtering to sources supplied by return types. Supply multiple to filter to multiple sources.
  • loc: filter to sources with greater lines of code then supplied int. Valid values 0 to 10000.
  • loc2: filter to sources with less lines of code then supplied int. Valid values 0 to 10000.

Examples (JSON)

https://searchcode.com/api/codesearch_I/?q=soup&p=1&per_page=100
Example Language Filter (Java and Javascript)
https://searchcode.com/api/codesearch_I/?q=test&lan=23&lan=22
Example Source Filter (Bitbucket and CodePlex)
https://searchcode.com/api/codesearch_I/?q=test&src=3&src=5
Example Lines of Code Filter (Between 500 and 1000)
https://searchcode.com/api/codesearch_I/?q=test&loc=500&loc2=1000

Example (JSONP)

https://searchcode.com/api/jsonp_codesearch_I/?q=soup&p=1&callback=myCallback

Return Field Definitions

searchterm
Searchterm supplied to the API though the use of the q parameter.
query
Identical to searchterm and include for historical reasons to maintain backwards compatibility.
matchterm
Identical to searchterm and include for historical reasons to maintain backwards 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. Is 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 avaliable 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 should get more accurate the deeper into the results you go and the more filters are used however.
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 this code was found in.
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 searchcodes location of the file.
md5hash
Calculated MD5 hash of the files contents.
lines
Contains line numbers and lines which match the searchterm. Keep in mind that lines immediate belwore and after the match are included. For example, if line 2 is found to match then lines 1 and 3 will be included as well. Where only the filename is a match for the search term upto the first 15 lines of the file will be returned.

Result (JSON)

{
    "matchterm": "soup",
    "previouspage": 0, 
    "searchterm": "soup",
    "query": "soup", 
    "total": 4,
    "page": 0,
    "nextpage": 1,
    "language_filters": [
        {
            "count": 3,
            "id": 3,
            "language": "HTML"
        },
        {
            "count": 1,
            "id": 123,
            "language": "JSON"
        },
        {
            "count": 1,
            "id": 19,
            "language": "Python"
        }
    ],
    "source_filters": [
        {
            "count": 5,
            "source": "Github",
            "id": 2
        }
    ],
    "results": [
        {
            "repo": "https://code.google.com/p/html5lib/",
            "linescount": 239,
            "location": "/python3/html5lib/treebuilders",
            "name": "html5lib",
            "language": "Python",
            "url": "https://searchcode.com/codesearch/view/24862775/",
            "md5hash": "b8e6b1d1f53d5e4f87995ebeb35b358c",
            "lines": {
                "4": "",
                "5": "warnings.warn(\"BeautifulSoup 3.x (as of 3.1) is not fully compatible with html5lib and support will be removed in the future\", DeprecationWarning)",
                "6": "",
                "7": "from BeautifulSoup import BeautifulSoup, Tag, NavigableString, Comment, Declaration",
                "8": "",
                "139": "class TextNode(Element):",
                "140": "    def __init__(self, element, soup):",
                "141": "        _base.Node.__init__(self, None)",
                "142": "        self.element = element",
                "143": "        self.soup = soup",
                "144": "    ",
                "150": "        if namespaceHTMLElements:",
                "151": "            warnings.warn(\"BeautifulSoup cannot represent elements in any namespace\", DataLossWarning)",
                "152": "        _base.TreeBuilder.__init__(self, namespaceHTMLElements)",
                "154": "    def documentClass(self):",
                "155": "        self.soup = BeautifulSoup(\"\")",
                "156": "        return Element(self.soup, self.soup, None)"
            },
            "id": 24862775,
            "filename": "soup.py"
        }
    ]
}

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.

JSON

https://searchcode.com/api/result/[codeid]/

Example (JSON)

https://searchcode.com/api/result/4061576/

Return Field Definitions

code
Source code for the requested id.

Result (JSON)

{
    "code": "# Compiled source #\n###################\n*.com\n*.class\n*.dll\n*.exe\n*.o\n*.so\n*.pyc\n\n# Packages #\n############\n# it's better to unpack these files and commit the raw source\n# git has its own built in compression methods\n*.7z\n*.dmg\n*.gz\n*.iso\n*.jar\n*.rar\n*.tar\n*.zip\n\n# Logs and databases #\n######################\n*.log\n*.sqlite\n\n# OS generated files #\n######################\n.DS_Store\n.DS_Store?\n._*\n.Spotlight-V100\n.Trashes\nehthumbs.db\nThumbs.db\n\n# Custom\n#################\n\n.installed.cfg\nbin\ndevelop-eggs\ndist\ndownloads\neggs\nparts\nsrc/*.egg-info\n#lib\nlib64\n"
}
  

Related Results

Returns an array of results given a searchcode unique code id which are considered to be duplicates. The matching is slightly fuzzy allowing so that small differences between files are ignored.

JSON

https://searchcode.com/api/related_results/[codeid]/

Example (JSON)

https://searchcode.com/api/related_results/4061576/

Return Field Definitions

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 files 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.

Result (JSON)

[
    {
        "reponame": "grit",
        "source": "Github",
        "sourceurl": "https://github.com/mojombo/grit",
        "hash": "da77d7031eeb2fef7aacb5610d3e0b6a",
        "location": "/assets/integration_test",
        "language": "Python",
        "linescount": 611,
        "id": 71,
        "filename": "test.py"
    }
]
  

Documentation Index (deprecated)

Queries the documentation index and returns at most 10 results. This API is deprecated. No updates or bug fixes will be applied but the API as such will remain operational.

JSON

https://searchcode.com/api/search_IV/?q=[searchterm]&p=[page]

JSONP

https://searchcode.com/api/jsonp_search_IV/?q=[searchterm]&p=[page]&callback=[myCallback]

Params

  • q: search term
  • p: result page starting at 0 through to 49
  • callback: callback function (JSONP only)

Example (JSON)

https://searchcode.com/api/search_IV/?q=php&p=1

Example (JSONP)

https://searchcode.com/api/jsonp_search_IV/?q=php&p=1&callback=myCallback

Return Field Definitions

searchterm
Searchterm supplied to the API though the use of the q parameter.
matchterm
Identical to searchterm and include for historical reasons to maintain backwards 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. Is always set to +1 the current page. To determine the end or the results query till no results are returned.
previouspage
Id of the offset of the previous page. If no previous page is avaliable 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.
results
Returns an array containing the matching documentation results.
synopsis
Code snippet or example of the matching result.
displayname
Display ready name of the type of result.
name
Name of the result.
url
URL to the result source. Usually is a deep link directly to the documentation.
type
Same as display name but in a format allowing for easier grouping.
icon
Legacy. Was used to display the favicon for the result.
namespace
Namespace of the code result if it exists.
description
A description of the function method or whatever the result is describing.

Result (JSON)

{
    "matchterm": "php explode",
    "previouspage": null,
    "searchterm": "php explode",
    "query": "php explode",
    "total": 2,
    "page": 0,
    "nextpage": 1,
    "results": [
        {
            "synopsis": " array explode ( string $delimiter , string $string [, int $limit ] ) ",
            "displayname": "PHP",
            "name": "explode",
            "url": "http://www.php.net/manual/en/function.explode.php",
            "type": "php",
            "icon": "php.ico",
            "namespace": "",
            "description": "(PHP 4, PHP 5) explode — Split a string by string"
        }
    ]
}