Skip to main content

A Python dependency analyzer for import parsing and metadata extraction.

Project description

README.md

fnet-import-parser

fnet-import-parser is a powerful Python dependency analyzer that parses import statements, extracts metadata, and provides insights into your project's dependencies. It supports detecting unused imports, resolving circular dependencies, and exporting results in structured formats like JSON or YAML.


Features

  • Dependency Analysis: Identifies and categorizes built-in, third-party, and local dependencies.
  • Unused Import Detection: Highlights unused imports for cleanup.
  • Metadata Extraction: Extracts metadata hints from comments above import statements.
  • Circular Dependency Detection: Warns about circular dependencies in the analyzed files.
  • Flexible Output Formats: Provides results in both JSON and YAML formats.

Installation

Install the package using pip:

pip install fnet-import-parser

Usage

Command-Line Interface (CLI)

The tool provides a CLI for analyzing Python files.

Basic Usage

fnet-import-parser --entry_file path/to/your_script.py --output_format json

Options

  • --entry_file: The entry point Python file for analysis (required).
  • --output_format: The format for the results (json or yaml).

Example

Input Script: example.py

import os
import sys
# @hint: requests (channel=pypi)
import requests
from mymodule import myfunc

Running the Command

fnet-import-parser --entry_file example.py --output_format json

Output (JSON)

{
  "all": [
    {
      "type": "builtin",
      "path": "os",
      "imported_by": [
        {
          "path": "example.py",
          "used": true,
          "line": 1
        }
      ]
    },
    {
      "type": "builtin",
      "path": "sys",
      "imported_by": [
        {
          "path": "example.py",
          "used": true,
          "line": 2
        }
      ]
    },
    {
      "type": "package",
      "path": "requests",
      "imported_by": [
        {
          "path": "example.py",
          "used": true,
          "line": 3
        }
      ],
      "metadata": {
        "package": "requests",
        "channel": "pypi"
      }
    },
    {
      "type": "local",
      "path": "mymodule",
      "imported_by": [
        {
          "path": "example.py",
          "used": true,
          "line": 4
        }
      ]
    }
  ],
  "unreferenced": [],
  "unnecessary": [],
  "required": {
    "builtin": [
      {
        "type": "builtin",
        "path": "os"
      },
      {
        "type": "builtin",
        "path": "sys"
      }
    ],
    "third-party": [
      {
        "type": "package",
        "path": "requests",
        "metadata": {
          "package": "requests",
          "channel": "pypi"
        }
      }
    ],
    "local": [
      {
        "type": "local",
        "path": "mymodule"
      }
    ]
  }
}

Python API

You can also use fnet-import-parser programmatically in your Python projects.

Example

from src.index import default

kwargs = {
    "entry_file": "path/to/your_script.py",
    "output_format": "yaml"
}
result = default(**kwargs)
print(result)

License

This project is licensed under the MIT License. See the LICENSE file for details.


This README provides a complete, concise, and user-friendly introduction to your project, ensuring anyone can easily understand and get started with it. 🚀

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

fnet_import_parser-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fnet_import_parser-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fnet_import_parser-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for fnet_import_parser-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cf34def29dd5761528e51310d48dc02a2d3d96526ff3ddb1f43e212bf72bf0b0
MD5 60f381ce1ae697ceb210162c2b348297
BLAKE2b-256 6905de8eb4ed2a30c5b22055e77e633e17d87757e93c09c2a86c5beb5f9b6d97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fnet_import_parser-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 690e59e2ca713bbe6dbaf5120cab541bffa4482bf8714c0c6536a2c21bbd119e
MD5 7d16361336e2eedd1b3381da7ef82652
BLAKE2b-256 1eb27173df1c90b9dac642c5dee6642fbc02296002ec97b97d18b8060024ed55

See more details on using hashes here.

Supported by

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