Skip to main content

License: MIT Last Commit PyPI PyPI Downloads

PyCodar: A Radar for Your Code

A simple tool for auditing and understanding your (python) codebase.

pip install pycodar
  • pycodar stats: Summarizes the most basic stats of your directory in a single table. 📊
  • pycodar strct: Displays the file structure of all the files, their functions, classes, and methods in a nicely colored tree. 🗂️
  • pycodar files: Shows a table of all the files with counts of the lines of code, comments, empty lines, total lines, and file size. 📋
  • pycodar calls: Counts how often elements (modules, functions, methods) of your code are called within the code. 📞
  • pycodar deps: Shows which external packages and standard library modules are used in your code. 📦
  • pycodar dead: Finds (likely) unused code. ☠️

General Overview

Type

pycodar stats

in your terminal to get the most basic statistics of your directory printed out:

📊 Basic Metrics
╭─────────────────────┬───────────╮
│  Total Size         │  54.21KB  │
│  Total Files        │  6        │
│  Total Directories  │  2        │
│  Total Lines        │  1,394    │
│  Code Lines         │  885      │
│  Comment Lines      │  26       │
│  Empty Lines        │  208      │
│  Functions          │  38       │
│  Classes            │  2        │
╰─────────────────────┴───────────╯

Structure

pycodar strct

gives you something like:

🌳 File Structure
📁 Root
├── 📄 README.md
├── 📄 pyproject.toml
├── 📄 setup.py
└── 📁 pycodar
    ├── 📄 __init__.py
    ├── 📄 analyze.py
    │   ├── 🔷 CodeElementVisitor
    │   │   ├── 🔹 __init__
    │   │   ├── 🔹 visit_FunctionDef
    │   │   ├── 🔹 visit_ClassDef
    │   │   ├── 🔹 visit_Import
    │   │   ├── 🔹 visit_ImportFrom
    │   │   ├── 🔹 visit_Call
    │   │   ├── 🔹 visit_Assign
    │   │   ├── 🔹 visit_Name
    │   │   ├── 🔹 visit_Attribute
    │   │   ├── 🔹 visit_Return
    │   │   └── 🔹 visit_Decorator
    │   ├── 🔸 count_functions_and_classes
    │   ├── 🔸 get_file_size_kb
    │   ├── 🔸 count_lines
    │   ├── 🔸 analyze_code_connections
    │   ├── 🔸 analyze_directory
    │   └── 🔸 generate_report
    └── 📄 cli.py
        ├── 🔷 TestClass
        │   ├── 🔹 __init__
        │   └── 🔹 test_method
        ├── 🔸 extract_code_structure
        ├── 🔸 create_structure_tree
        ├── 🔸 parse_ignore_file
        ├── 🔸 should_ignore
        ├── 🔸 get_ignore_patterns
        ├── 🔸 format_size
        ├── 🔸 count_code_metrics
        ├── 🔸 create_metrics_table
        ├── 🔸 create_code_connections_table
        ├── 🔸 create_dead_code_table
        ├── 🔸 create_code_connections_tree
        ├── 🔸 create_file_table
        ├── 🔸 print_stats
        ├── 🔸 print_structure
        ├── 🔸 print_files
        ├── 🔸 print_calls
        ├── 🔸 print_dead_code
        ├── 🔸 process_directory
        └── 🔸 main

File Statistics

Typing

pycodar files

will give you an overview of the lines of code, comments, empty lines, total lines and file sizes:

📁 File Distribution
╭───────────┬──────────────────┬────────┬────────────┬─────────┬─────────┬───────────╮
│  Path     │  File            │  Code  │  Comments  │  Empty  │  Total  │     Size  │
├───────────┼──────────────────┼────────┼────────────┼─────────┼─────────┼───────────┤
│  Root     │  pyproject.toml  │     0  │         0  │      0  │     43  │   1.37KB  │
│  Root     │  README.md       │     0  │         0  │      0  │     95  │   3.37KB  │
│  Root     │  setup.py        │    45  │         0  │      1  │     46  │   1.72KB  │
│  pycodar  │  __init__.py     │     7  │         1  │      3  │     11  │   0.22KB  │
│  pycodar  │  cli.py          │   384  │        18  │     90  │    492  │  18.62KB  │
│  pycodar  │  analyze.py      │   449  │         7  │    114  │    570  │  22.27KB  │
╰───────────┴──────────────────┴────────┴────────────┴─────────┴─────────┴───────────╯

Calls

To check how much the modules, functions and methods in your code are actually being used, type:

pycondar calls

which will give you another table like:

📊 Most Called Elements
╭────────────┬─────────────────────────┬──────────╮
│  Type      │  Name                   │  Called  │
├────────────┼─────────────────────────┼──────────┤
│  Function  │  isinstance             │      28  │
│  Function  │  print                  │      22  │
│  Function  │  defaultdict            │      17  │
│  Function  │  set                    │      11  │
│  Function  │  sorted                 │      10  │
│  Function  │  len                    │      10  │
│  Function  │  str                    │       9  │
│  Function  │  open                   │       7  │
│  Function  │  Path                   │       4  │
│  Function  │  sum                    │       4  │
│  Method    │  console.print          │      22  │
│  Method    │  table.add_row          │      15  │
│  Method    │  table.add_column       │      14  │
│  Method    │  self.generic_visit     │       8  │
│  Method    │  ast.walk               │       5  │
│  Method    │  subparsers.add_parser  │       5  │
│  Method    │  ast.parse              │       4  │
│  Method    │  tree.add               │       4  │
│  Method    │  method.startswith      │       4  │
│  Method    │  file.read              │       3  │
╰────────────┴─────────────────────────┴──────────╯

Dead Code

And finally, to see if there is any code that's not even used, type

💀 Potentially Unused Code
╭─────────┬─────────────────────────╮
│  Type   │  Name                   │
├─────────┼─────────────────────────┤
│  Class  │  pycodar.cli.TestClass  │
╰─────────┴─────────────────────────╯

which will point you at whatever code seems to be unused.


If you need any help / a quick reminder, type:

pycodar help

and if you just want to see everything all at once, type:

pycodar all

Thank you and enjoy! 😜

Metadata

Release files for pycodar 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for pycodar 0.1.7
File Interpreter ABI Platform Actions
pycodar-0.1.7-py3-none-any.whl Python 3 none any Details for pycodar-0.1.7-py3-none-any.whl

Release files / pycodar-0.1.7-py3-none-any.whl

Download URL pycodar-0.1.7-py3-none-any.whl
Size 15.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bff5fbb5b73db235331e5f58d336fdf8712029fb3ae423a8fe75813f92538f97
BLAKE2b-256 checksum
How to use checksums
1404a8d6d26275e40fb3f228b42a2bdf7a1ab83dd0e5f7d31106c8cb2e53b9c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Security for pycodar 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page