Have you ever found yourself desperately searching for that one elusive method or variable in a complex Python codebase? You know it’s there somewhere, but it seems to be playing a game of hide-and-seek, leaving you frustrated and wasting precious time scrolling through pages of documentation and source code.
What is Search’In?
Search’In is a tool that allows you to search in live python objects as if you were on Google, just by adding a line in the middle of your code !
To begin, you’ll need to install Search’In using pip
:
pip install searchin
Import it into your Python code with just one line:
import searchin
Imagine you have a Human
class, and you're searching for the method or variable named "name." Just do:
searchin(Human, "name")
No, you’re not hallucinating: the module is the function. 11 characters saved ;-)
You can search for any string in any python “entity” : variable, method, object, class, module, etc.
Search for "5"
in a tuple
:
searchin((1, 2, 3, 4, 5, 6, 7, 8, 9), "5")
# >>> "5" found in root.4 : 5
Search for "mean"
in the method torch.nn.functional.cross_entropy
:
searchin(torch.nn.functional.cross_entropy, "mean")
# "mean" found in cross_entropy. : def cross_entropy( [...] reduction: str = "mean", [...], label_smoothing)
Search for "grad"
in a torch.nn.Module
:
model = torch.nn.Linear(10, 10)
searchin(model, "grad")
# "grad" found in model.bias
# "grad" found in model.requires_grad_
# "grad" found in model.weight
# "grad" found in model.zero_grad
Hope this will be useful to you! ==> https://pypi.org/project/searchin/
The project could have a lot more useful functionnalities. Contributions are welcome! ==> https://github.com/NicolasMICAUX/searchin
Maybe this new tool is similar to existing ones, that I’m not aware of ==> if so, I would be happy to know which :)
Top comments (0)