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.
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.
The only condition of using the searchcode API is to provide a clickable link attributing searchcode as the source. Sadly rate limiting is implemented due to abuse. The limits are fairly generous but when reached you will receive an empty JSON object with 429 HTTP response. Subsequent requests will increase the timout period. If you get a 429 you should exponentially back-off your calls and before trying again. Operate as Bill and Ted would and "Be excellent to each other".
Generally speaking corporate usage using the searchcode API is not an issue. However if you are running a company with business critical functions using the API and want to ensure the service is still running next week, contact Ben via ben@boyter.org and we can work some form of commercial licence out.
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
Examples (JSON)
https://searchcode.com/api/codesearch_I/?q=soup&p=1&per_page=100Example Language Filter (Java and Javascript)
https://searchcode.com/api/codesearch_I/?q=test&lan=23&lan=22Example Source Filter (Bitbucket and CodePlex)
https://searchcode.com/api/codesearch_I/?q=test&src=3&src=5Example Lines of Code Filter (Between 500 and 1000)
https://searchcode.com/api/codesearch_I/?q=test&loc=500&loc2=1000Return Field Definitions
{
"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"
}
]
}
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": "# 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"
}
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": "grit",
"source": "Github",
"sourceurl": "https://github.com/mojombo/grit",
"hash": "da77d7031eeb2fef7aacb5610d3e0b6a",
"location": "/assets/integration_test",
"language": "Python",
"linescount": 611,
"id": 71,
"filename": "test.py"
}
]