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.0.3.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.0.3-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fnet_import_parser-0.0.3.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.0.3.tar.gz
Algorithm Hash digest
SHA256 31d1cf166c649841198b0498b359dae285248b01806a543631e6bceb840a6c48
MD5 fcc53dbbe1c102c957e84cefa2799412
BLAKE2b-256 3664a8cfa8fdbb8e54d372a6f0a14a99a75b50acfa8c9cab1dc5bbee2c307923

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fnet_import_parser-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 69228146d9530987e5b84b8ccaf6f307876b59603013313e27bc588d9b27bb99
MD5 3d331de72b46b426b111cc5e377f9282
BLAKE2b-256 d18ec489182a39731b0b1520af5d1d328491392b7de5cd230881787dc1c0a636

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