Skip to main content


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"
  • page: Result page starting at 0 through to 49
  • per_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 page parameter 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.

Learn more

Credits

This SDK is developed and maintained by Ritchie Mwewa, in collaboration with Ben Boyter, the creator of Searchcode.com.

Metadata

Release files for searchcode 0.6.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for searchcode 0.6.4
File Size Uploaded
searchcode-0.6.4.tar.gz 36.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for searchcode 0.6.4
File Interpreter ABI Platform
searchcode-0.6.4-py3-none-any.whl Python 3 none any Details

Total release size: 77.1 kB

Release files / searchcode-0.6.4.tar.gz

Download URL searchcode-0.6.4.tar.gz
Size 36.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7d775ee93f785d2e92f860fdbaa511f6ff269cee37c31494baa9392f0b882e9d
BLAKE2b-256 checksum
How to use checksums
fd0dc347de4a870204aa83a28600d42cb72916b6fb114b198e840bfb3246e068
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / searchcode-0.6.4-py3-none-any.whl

Download URL searchcode-0.6.4-py3-none-any.whl
Size 40.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aad58530287abccb05a9cd1afba09dfd39fbe2e0ed0dcd8a5d16acb46199e8ba
BLAKE2b-256 checksum
How to use checksums
7aeb0a71a9c8b9ebf4c1514b0c78e6cbf121f722a3732fa9ef60ded5acb1bbb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.6.4 This release

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page