Skip to main content

Python Toolkit to imports introspection

Project description

Py-Imports

Parse imports from .py file in a flexible way

Test Coverage Package version Supported Python versions


Source Code: https://github.com/andresbena19/py-imports

Requirements

Python 3.7+

py-imports stands on the shoulders of giants:

Installation

$ pip install py-imports

---> 100%

All it's ready to begin 

Example

Introspect it

  • Create a file main.py with:
from py_imports.manager import PyImports

myself = "main.py"

# Let's introspect myself
with PyImports() as manager:
    manager.get_imports(myself)
    imports = manager.imports_resume()


# Now you have access to the imports used in each file 
print(imports)
{
 'main.py': <py_imports.base.models.ImportsCollectionFile object at 0x10b889220>
}

# Get details about the absolute, relative and standard imports in the file
collector_object = imports.get(myself)
absolute_imports = collector_object.absolute_imports
relative_imports = collector_object.relative_imports
imports = collector_object.imports

# It's obvious that in this file there are just one absolute import
#  --- from py_imports.manager import PyImports ---
# If we introspect the object, we will get the next

first_import = absolute_imports[0]
first_import.childs -> ['PyImports']
first_import.parent -> 'py_imports.manager'
first_import.statement -> 'from py_imports.manager import PyImports'
first_import.level -> 0
first_import.line -> 1

# Now you know more about you...

License

This project is licensed under the terms of the MIT license.

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

py_imports-1.0.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

py_imports-1.0.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file py_imports-1.0.0.tar.gz.

File metadata

  • Download URL: py_imports-1.0.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.10.0 Linux/5.11.0-1020-azure

File hashes

Hashes for py_imports-1.0.0.tar.gz
Algorithm Hash digest
SHA256 685d396522f7b1e1a7074fdc430868d1812de6907dcd861533af958e0714851f
MD5 ec5589de73a483c3d20b1bc20d30ebdc
BLAKE2b-256 eeea23eae0ec80fd0b65c20923670634bb2e34b80b463ee9fd3a721088e0b9a8

See more details on using hashes here.

File details

Details for the file py_imports-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: py_imports-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.10.0 Linux/5.11.0-1020-azure

File hashes

Hashes for py_imports-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7362f35dc5a82a0af9f49b12cdc651057d62d2b2233ec2706faabd8726979bf1
MD5 53f5635ce9ac08351b4bceadc950661e
BLAKE2b-256 e6134eeb5511c9aba326507278beb8a374e21ebf30a4c0202af5cd8642427f09

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page