https://github.com/nicolasmicaux/searchin
Search anything in a live python object/method/variable!
https://github.com/nicolasmicaux/searchin
debug debugging-tool inspect python searching
Last synced: 6 months ago
JSON representation
Search anything in a live python object/method/variable!
- Host: GitHub
- URL: https://github.com/nicolasmicaux/searchin
- Owner: NicolasMICAUX
- Created: 2022-10-19T13:29:41.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-24T15:36:29.000Z (about 1 year ago)
- Last Synced: 2025-04-23T18:09:06.007Z (6 months ago)
- Topics: debug, debugging-tool, inspect, python, searching
- Language: Python
- Homepage:
- Size: 84 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.fr.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
[![Contributors][contributors-shield]][contributors-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![PyPi version][pypi-shield]][pypi-url]
[![Python 2][python2-shield]][python-url]
[![Python 3][python3-shield]][python-url]
Search'In
Cherchez ce que vous voulez dans un objet, méthode ou variable python, directement dans votre code !
## Introduction
Avez vous déjà passé des heures à chercher le nom d'une méthode ou d'une propriété d'une librairie tierce ? Vous êtes sûr que cette méthode/propriété doit exister, mais impossible de la trouver, ni dans la documentation, ni dans les exemples, ni sur StackOverflow... Vous finissez par vous résigner à scroller dans le code source de la librairie... Tellement frustrant !
Search'In est un outil qui vous permet de rechercher dans des objets python comme si vous étiez sur Google, juste en ajoutant une ligne en plein milieu de votre code !
## Pour commencer
Utiliser Search'In ne recquiert aucun effort.
Installer Search'In avec pip :
```sh
pip install searchin
```
Importer Search'In dans votre code, en ajoutant cette ligne :
```python
import searchin
```
Pour chercher `"name"` dans une classe `Human` par exemple, il suffit d'ajouter cette ligne :
```python
searchin(Human, "name")
```
## D'autres exemples
Vous pouvez chercher n'importe quelle chaîne de caractère dans n'importe quel "entité" python : variable, méthode, objet, classe, module, etc.
**Chercher `"5"` dans un `tuple`**
```python
searchin((1, 2, 3, 4, 5, 6, 7, 8, 9), "5")
# >>> "5" found in root.4 : 5
```
**Chercher `"mean"` dans la méthode `torch.nn.functional.cross_entropy`**
```python
searchin(torch.nn.functional.cross_entropy, "mean")
# >>> "mean" found in root. : def cross_entropy( [...] reduction: str = "mean", [...], label_smoothing)
```
**Chercher `"grad"` dans un `torch.nn.Module`**
```python
model = torch.nn.Linear(10, 10)
searchin(model, "grad")
# >>> "grad" found in root.bias
# >>> "grad" found in root.requires_grad_
# >>> "grad" found in root.weight
# >>> "grad" found in root.zero_grad
```
## Fonctionnalités avancées
```python
def searchin(obj,
query: str,
max_depth: int = 3,
top_k_results: int = 10,
max_iterable_length: int = 100,
get_raw_result: bool = False) -> Union[List[SearchResult], None]:
"""
Search an object for a given search term.
:param obj: The object to search in.
:param query: What to search for.
:param max_depth: The maximum depth of the recursive search.
:param top_k_results: The maximum number of results to return.
:param max_iterable_length: The maximum length of an iterable to search in.
:param get_raw_result: If True, return the raw results (of type SearchResult), else just print them.
:return: A list of search results.
"""
```
## Contributing
_(Section in english)_
I want to add a lot of functionnalities to this project, but I don't have much time to work on it. Contributions are welcome!
### Roadmap/todo
| Task | Importance | Difficulty | Contributor on it | Description |
|:-------------------------|------------|------------|-------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------|
| [Fuzzy match](https://github.com/NicolasMICAUX/searchin/discussions/2) | 5/5 | 2/5 | NOBODY | _e.g._ : `batch_size` should match when searching `batchsize`. |
| [Underline the match](https://github.com/NicolasMICAUX/searchin/discussions/4) | 4/5 | 1/5 | NOBODY | _e.g._ : the printed result should be formatted like this : _def cross_entropy( [...] reduction: str = "mean", [...], label_smoothing)_ |
| [Write some tests](https://github.com/NicolasMICAUX/searchin/discussions/5) | 4/5 | 2/5 | NOBODY | Write some tests to ensure that the code is working properly. |
| [Find a better algorithm](https://github.com/NicolasMICAUX/searchin/discussions/7) | 3/5 | 4/5 | NOBODY | The current algorithm is a BFS (Breadth First Search). Maybe there is a better algorithm to use. |
| [`Searchin...` animation](https://github.com/NicolasMICAUX/searchin/discussions/9) | 3/5 | 1/5 | NOBODY | Add a cool animation when searching takes a bit of time. |
| [Profile code](https://github.com/NicolasMICAUX/searchin/discussions/11) | 2/5 | 1/5 | NOBODY | Profile the code to see if we can speed it up a little. |
| [Add a CLI](https://github.com/NicolasMICAUX/searchin/discussions/12) | 1/5 | 2/5 | NOBODY | Think about the design of a CLI (Command Line Interface) to use Search'In from the terminal. |
Non-Code contribution :
| Task | Importance | Difficulty | Contributor on it | Description |
|:-------------------------|------------|------------|-------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Adding documentation](https://github.com/NicolasMICAUX/searchin/discussions/6) | 4/5 | 1/5 | NOBODY | Add some helpful docstrings, write basic tutorials with real-life scenarios, write a wiki for other contributors to better understand the functioning of the library. |
_For every todo, just click on the link to find the discussion where I describe how I would do it._
See the [open issues](https://github.com/NicolasMICAUX/searchin/issues) for a full list of proposed features (and known issues).
### How to contribute
Contributing is an awesome way to learn, inspire, and help others. Any contributions you make are **greatly appreciated**, even if it's just about styling and best practices.
If you have a suggestion that would make this project better, please fork the repo and create a pull request.
Don't forget to give the project a star! Thanks again!
1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/YourAmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
## Auteurs
Cette librairie a été crée par [Nicolas MICAUX](https://github.com/NicolasMICAUX).
[contributors-shield]: https://img.shields.io/github/contributors/NicolasMICAUX/searchin.svg?style=for-the-badge
[contributors-url]: https://github.com/NicolasMICAUX/searchin/graphs/contributors
[stars-shield]: https://img.shields.io/github/stars/NicolasMICAUX/searchin.svg?style=for-the-badge
[stars-url]: https://github.com/NicolasMICAUX/searchin/stargazers
[issues-shield]: https://img.shields.io/github/issues/NicolasMICAUX/searchin.svg?style=for-the-badge
[issues-url]: https://github.com/NicolasMICAUX/searchin/issues
[pypi-shield]: https://img.shields.io/pypi/v/searchin.svg?style=for-the-badge
[pypi-url]: https://pypi.org/project/searchin/
[python2-shield]: https://img.shields.io/badge/python-2.7+-blue.svg?style=for-the-badge
[python3-shield]: https://img.shields.io/badge/python-3.5+-blue.svg?style=for-the-badge
[python-url]: https://www.python.org/downloads/
[//]: # ([license-shield]: https://img.shields.io/github/license/NicolasMICAUX/searchin.svg?style=for-the-badge)
[//]: # ([license-url]: https://github.com/NicolasMICAUX/searchin/blob/master/LICENSE.txt)
[//]: # ([linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555)
[//]: # ([linkedin-url]: https://linkedin.com/in/othneildrew)
[product-screenshot]: images/screenshot.png