Extract imported libraries from Python, R, and other source code files using tree-sitter.
Project description
Extract Imported Libraries
Small Python utility to extract imported libraries from source code files in various programming languages using tree-sitter.
Supported Languages
- Python
- R
Installation
You can install the package via pip:
pip install pyeil
Usage
Single File
from eil import Extractor
extractor = Extractor()
imported_libs = extractor.extract_from_file("path/to/your/file.py")
print(imported_libs)
# Output:
# ImportedLibraries(
# stdlib={'os', 'sys'},
# third_party={'requests', 'pandas'},
# first_party={'utils'},
# )
Directory Processing
Extract imports from all files in a directory with optional progress bar:
from eil import Extractor, ExtractorType
extractor = Extractor()
# Extract from all supported files in a directory
result = extractor.extract_from_directory(
"src/",
extractor_type=ExtractorType.ALL, # or PYTHON, R
recursive=True, # search subdirectories
show_progress=True, # show tqdm progress bar
)
# Access results
for file_path, libs in result.extracted.items():
print(f"{file_path}: {libs.third_party}")
# Check for failures
for file_path, error in result.failed.items():
print(f"Failed: {file_path}\n{error}")
Processing Notebook Formats
If you want to extract imports from Jupyter notebooks or Rmd files, you should first convert them to their script counterparts using: py-nb-to-src which will convert .ipynb of all types (R, Julia, Python, Matlab) to their respective script formats as well as .Rmd to .R scripts.
Install with: pip install py-nb-to-src
Then use the following code to convert and extract imports:
from py_nb_to_src import convert_directory, ConverterType
from pyeil import Extractor
converted_file_results = convert_directory(
"notebooks/",
recursive=True,
progress_leave=False,
)
extractor = Extractor()
extracted_results = extractor.extract_from_directory(
"notebooks/",
recursive=True,
progress_leave=False,
)
for file_path, libs in extracted_results.extracted.items():
print(f"{file_path}: {libs.third_party}")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyeil-0.2.0.tar.gz.
File metadata
- Download URL: pyeil-0.2.0.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91df381922b411814df388573d4f6b4e661e2e0cd8a107c47c33ee196a678056
|
|
| MD5 |
5ba8f3213e519f5cb0f8517c97ecdd97
|
|
| BLAKE2b-256 |
a838b49edc2adc3049005094b7dc24fdf18162e19a11308a41f705d9b782bd2b
|
Provenance
The following attestation bundles were made for pyeil-0.2.0.tar.gz:
Publisher:
ci.yml on evamaxfield/py-extract-imported-libraries
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyeil-0.2.0.tar.gz -
Subject digest:
91df381922b411814df388573d4f6b4e661e2e0cd8a107c47c33ee196a678056 - Sigstore transparency entry: 835753634
- Sigstore integration time:
-
Permalink:
evamaxfield/py-extract-imported-libraries@d3fec9ceedbf4a23a3307218a99afc33a7ad3391 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/evamaxfield
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@d3fec9ceedbf4a23a3307218a99afc33a7ad3391 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyeil-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pyeil-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a72936b182aa0ca27d4cf7d6e9fd6c9cac782b8f6b09f546ce5b18fee830034
|
|
| MD5 |
772ea341a1bd8c7478482be8603ff04b
|
|
| BLAKE2b-256 |
e2f72e9d2c846e33269a346c8413fd3fc8dcb90d9eb755e83c0f92706e3da401
|
Provenance
The following attestation bundles were made for pyeil-0.2.0-py3-none-any.whl:
Publisher:
ci.yml on evamaxfield/py-extract-imported-libraries
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyeil-0.2.0-py3-none-any.whl -
Subject digest:
3a72936b182aa0ca27d4cf7d6e9fd6c9cac782b8f6b09f546ce5b18fee830034 - Sigstore transparency entry: 835753638
- Sigstore integration time:
-
Permalink:
evamaxfield/py-extract-imported-libraries@d3fec9ceedbf4a23a3307218a99afc33a7ad3391 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/evamaxfield
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@d3fec9ceedbf4a23a3307218a99afc33a7ad3391 -
Trigger Event:
push
-
Statement type: