Skip to main content
GitHub last commit GitHub license<space><space> Documentation Status https://travis-ci.org/stas-prokopiev/code_searcher.svg?branch=master PyPI PyPI - Python Version

Short Overview.

code_searcher is a simple Python package(py>=2.7 or py>=3.4) with the main purpose to make searching through your project codebase fast and simple.

Currently, fully supported file types are .py and .ipynb nonetheless, search functional can be applied to any file extensions which can be read as plain text in utf-8 encoding.

In additional it allows you to get some useful info about your project codebase. For more info check section: Typical examples of Usage

More info.

The main reason of building this package was to create universal tool to help support changes in methods signatures in both .py and .ipynb files.

It’s becoming quite useful when your project outgrows 1k lines of code and manual replacement becomes too annoying (Too easy to overlook replacement somewhere).

For more info check section: Typical examples of Usage

Installation

  • Install via pip:

pip install code_searcher

Typical examples of Usage

In any case, the first thing you need to do is to import the necessary module and initialize class obj.
To do so you need to give pathes to folders in which all your files located (searcher will look deeper to full extent).

If you have a code of all your projects structured that there is the main folder for all .py files and there is the main folder for all .ipynb files then use them.

from code_searcher import CodeSearcher
LIST_STR_FOLDERS_WHERE_TO_LOOK = ["path_to_dir_1", "path_to_dir_1", ...]
code_searcher_obj = CodeSearcher(
        LIST_STR_FOLDERS_WHERE_TO_LOOK,
        list_str_file_extensions=[".py", "ipynb"],
)

Please note that first initialization can be a long process if the folders where you search for files are deep and wide.

But after finding all files they won’t be downloaded again unless they were changed. So excellent performance is expected.

1) To find all occurrences of some code.

E.G. You’ve changed a function signature and want to do necessary changes in the library.

To find all the places where this function was used use the code below

code_searcher_obj.search("line_to_look_for")

Output:

===============================================================================
For folder: c:\users\stanislav\desktop\my_python_projects\code_search_engine\project\code_searcher\src\code_searcher

--> For extension: .py
----> Found in:  CodeSearcher.py
------> 0) line: 93  Code_line: line_to_look_for(
------> 1) line: 444  Code_line: def line_to_look_for(

--> For extension: ipynb
----> NOTHING FOUND.
===============================================================================
Overall occurrences found:  2

2) To find all occurrences of some regular expression pattern

code_searcher_obj.search_with_re("^from __future__ import[\s]+")

Output:

===============================================================================
For folder: c:\users\stanislav\desktop\my_python_projects\code_search_engine\project\code_searcher\src\code_searcher

    --> For extension: .py
    ----> Found in:  additional_functions.py
    ------> 0) line: 12  Code_line: from __future__ import print_function
    ----> Found in:  CodeSearcher.py
    ------> 1) line: 11  Code_line: from __future__ import print_function
    ----> Found in:  decorators.py
    ------> 2) line: 12  Code_line: from __future__ import print_function
    ----> Found in:  working_with_files.py
    ------> 3) line: 12  Code_line: from __future__ import print_function

    --> For extension: ipynb
    ----> NOTHING FOUND.
===============================================================================
Overall occurrences found:  4

3) To see some statistics about your library.

print(code_searcher_obj)

Output:

Folders to search in:
--> c:\users\stanislav\desktop\my_python_projects\code_searcher\src\code_searcher
--> c:\users\stanislav\desktop\my_python_projects\code_searcher\jupyter_notebooks

Extensions to check:
--> .py
--> .ipynb

===============================================================================
Files Statistic of current code library:
===============================================================================
--> For folder: c:\users\stanislav\desktop\my_python_projects\code_searcher\src\code_searcher
--> Files_found = 4  Code_lines = 664
----> .py:  Files_found = 4;  Code_lines = 664;
----> .ipynb:  Files_found = 0;  Code_lines = 0;
===============================================================================
--> For folder: c:\users\stanislav\desktop\my_python_projects\code_searcher\jupyter_notebooks
--> Files_found = 1  Code_lines = 22
----> .py:  Files_found = 0;  Code_lines = 0;
----> .ipynb:  Files_found = 1;  Code_lines = 22;
===============================================================================

4) To add new files to examine.

If you’ve created a new file inside folder given to code_searcher then you should update files for code_searcher

code_searcher_obj.update_files()

5) To get dictionary with content of all satisfy files.

For now on this dictionary structure is

{“dir_path_1”: {“file_extension_1”: {“absolute_file_path_1”: str_file_content, ..}, ..}, ..}

code_searcher_obj.dict_str_file_by_path_by_ext_by_dir

Contacts

License

This project is licensed under the MIT License.

Release files for code-searcher 0.2.1

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

Source distribution (sdist)

Source distribution for code-searcher 0.2.1
File Size Uploaded
code_searcher-0.2.1.tar.gz 20.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for code-searcher 0.2.1
File Interpreter ABI Platform
code_searcher-0.2.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 31.8 kB

Release files / code_searcher-0.2.1.tar.gz

Download URL code_searcher-0.2.1.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
498d020610752206aec64941ee8e838a344f1f4a2094ddde1ccce313cb9364a7
BLAKE2b-256 checksum
How to use checksums
846c311794cda3d311bf6930b23e6fe374819c7e5901bcd609cf918724a8db88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

Release files / code_searcher-0.2.1-py2.py3-none-any.whl

Download URL code_searcher-0.2.1-py2.py3-none-any.whl
Size 11.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b807026d27538c7f703cb01531aa98dbec56a2653688e604c4035f8b09a4578d
BLAKE2b-256 checksum
How to use checksums
a27c61e3cbbdd7c25140ee408a512b407d1960079649846a6bb4cf2e33bafb30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.16

2 release files

0.1.13

2 release files

0.1.11

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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