Skip to main content

Python Toolkit to imports introspection

Project description

Py-Imports

Parse imports from .py file in a flexible way

Test Coverage


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-0.1.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

py_imports-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_imports-0.1.0.tar.gz
  • Upload date:
  • Size: 6.9 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-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b9ef3f4c110202aa54e0bf4f844b50e801334a8f4afb4be527352d5eada2a5ff
MD5 5cbda9777336d4195091ae5745ad3161
BLAKE2b-256 51a357d3acc9211c8825914faa0fc890a2e267450ded9bce316438165a263647

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_imports-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 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-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed5f1feda4145a523a58f74619c4ed343317020b01b39dc0507f911b88dbe70f
MD5 1c60f47b75d710fe605849a14f2e339f
BLAKE2b-256 fc8a08b7972ba4e4f7942bbe337ac3261b824b9d878f735719604d1883bc78db

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