Simple, comprehensive code search
Project description
Searchcode Python: Python library and CLI utility for Searchcode.
Simple, comprehensive code search.
searchcode.com is being rebooted
After many years of helping developers find code snippets and examples, the time has come to reboot searchcode.com
For a more detailed explanation of why this is happening, please read the full blog post: searchcode is being rebooted
searchcode search "import module"
Or simply:
sc search "import module"
from pprint import pprint
from searchcode import Searchcode
sc = Searchcode(user_agent="My-Searchcode-script")
search = sc.search(query="import module")
pprint(search)
Installation
pip install searchcode
Getting Started
Code Search Without Filters
Command-Line Interface
searchcode "import module"
In Code
from pprint import pprint
from searchcode import Searchcode
sc = Searchcode(user_agent="My-Searchcode-script")
search = sc.search(query="import module")
pprint(search)
Filter by Language (Java and JavaScript)
Command-Line Interface
searchcode "import module" --languages java,javascript
In Code
from pprint import pprint
from searchcode import Searchcode
sc = Searchcode(user_agent="My-Searchcode-script")
search = sc.search(query="import module", languages=["Java", "JavaScript"])
for result in search.results:
pprint(result.language)
Filter by Source (BitBucket and CodePlex)
Command-Line Interface
searchcode "import module" --sources bitbucket,codeplex
In Code
from pprint import pprint
from searchcode import Searchcode
sc = Searchcode(user_agent="My-Searchcode-script")
search = sc.search(query="import module", sources=["BitBucket", "CodePlex"])
for result in search.results:
pprint(result.filename)
Filter by Lines of Code (Between 500 and 1000)
Command-Line Interface
searchcode "import module" --lines-of-code-gt 500 --lines-of-code-lt 1000
In Code
from pprint import pprint
from searchcode import Searchcode
sc = Searchcode(user_agent="My-Searchcode-script")
search = sc.search(query="import module", lines_of_code_gt=500, lines_of_code_lt=1000)
for result in search.results:
pprint(result)
With Callback Function (JSONP only)
Command-Line Interface
searchcode "import module" --callback myCallback
In Code
from pprint import pprint
from searchcode import Searchcode
sc = Searchcode(user_agent="My-Searchcode-script")
search = sc.search(query="import module", callback="myCallback")
pprint(search)
Params
query: Search term (required).- 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"
- The following filters are textual and can be added into query directly
page: Result page starting at 0 through to 49per_page: Number of results wanted per page (max 100).languages: List of programming languages to filter by.sources: List of code sources (e.g., GitHub, BitBucket).lines_of_code_gt: Filter to sources with greater lines of code than supplied int. Valid values 0 to 10000.lines_of_code_lt: Filter to sources with less lines of code than supplied int. Valid values 0 to 10000.callback: Callback function (JSONP only)
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
pageparameter until you get a page with an empty results list.
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.
Command-Line Interface
searchode code 4061576
In Code
Params
_id: Unique identifier for the code file (required).
from searchcode import Searchcode
sc = Searchcode(user_agent="My-Searchcode-script")
data = sc.code(4061576)
print(data.language)
print(data.code)
About Searchcode
Searchcode is a simple, comprehensive source code search engine that indexes billions of lines of code from open-source projects, helping you find real world examples of functions, API's and libraries in 243 languages across 10+ public code sources.
Credits
This SDK is developed and maintained by Ritchie Mwewa, in collaboration with Ben Boyter, the creator of Searchcode.com.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file searchcode-0.6.4.tar.gz.
File metadata
- Download URL: searchcode-0.6.4.tar.gz
- Upload date:
- Size: 36.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d775ee93f785d2e92f860fdbaa511f6ff269cee37c31494baa9392f0b882e9d
|
|
| MD5 |
0d5416eb00e8e3cdeb9b17fdecce975e
|
|
| BLAKE2b-256 |
fd0dc347de4a870204aa83a28600d42cb72916b6fb114b198e840bfb3246e068
|
File details
Details for the file searchcode-0.6.4-py3-none-any.whl.
File metadata
- Download URL: searchcode-0.6.4-py3-none-any.whl
- Upload date:
- Size: 40.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aad58530287abccb05a9cd1afba09dfd39fbe2e0ed0dcd8a5d16acb46199e8ba
|
|
| MD5 |
f521f0747b340add706900a537743758
|
|
| BLAKE2b-256 |
7aeb0a71a9c8b9ebf4c1514b0c78e6cbf121f722a3732fa9ef60ded5acb1bbb5
|