Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search github file contents by filename

Tags:

github

I am trying to identify use cases of a specific python package on github.

Is there a way you could search all requirements.txt files on repositories written in python for a string ?

like image 362
Decebal Avatar asked Sep 07 '25 16:09

Decebal


2 Answers

From the Web UI

In https://github.com/search, type :

django filename:requirements.txt language:python in:requirements.txt

like this : enter image description here

From Github API

https://api.github.com/search/code?q=django+in:requirements.txt+filename:requirements.txt+language:python+org:openmicroscopy

For the Github API case, you have to give a user, an organization or a repository

Check Search Code doc

Note that filename filter & string data are no exact match

like image 69
Bertrand Martel Avatar answered Sep 10 '25 05:09

Bertrand Martel


It's 2022 and GitHub search has changed a bit.

You can now just use the more flexible path: operator like this:

path:/^requirements.txt$/  django

Search results here. By default a search term now searches both the filename and the content, so to limit it to just filename/path we use path:. Also we use a regex to specify we want files named exactly requirements.txt and not things like dev-requirements.txt which path:requirements.txt would match.

I couldn't find a way to just search for requirements files in Python repos though. You can specify a language with language:python but that applies at a per-file level, not at the repo level and those files aren't Python themselves. Fortunately requirements.txt files seem to almost entirely be used in Python projects.

More info on GitHub's powerful new search can be found here.

like image 43
Chris Avatar answered Sep 10 '25 06:09

Chris