Skip to main content

Parse code to get information about functions, etc.

Project description

Python Code Parser

Parse Python code to extract information about functions, classes, methods, etc.

Install with pip

pip install python_code_parse

Usage

Below is the output of running the parser on the example examples/basic_example.py:

from python_code_parse import get_all_function_info_from_code, FunctionInfo
from typing import List

with open("examples/basic_example.py", "r") as f:
    data = f.read()

function_infos: List[FunctionInfo] = get_all_function_info_from_code(data)

print(function_infos)

"""
[
  FunctionInfo(
    name='sum',
    args=[
      FunctionArg(name='a', annotation='int'),
      FunctionArg(name='b', annotation='')
      ],
      return_type='None',
      line=1
    ),
    FunctionInfo(
      name='subtract',
      args=[
        FunctionArg(name='a', annotation=''),
        FunctionArg(name='b', annotation='')
      ],
      return_type='int',
      line=4
    )
]
"""

Setup for Development

python3 -m venv venv
source venv/bin/activate
pip install -e .
pip install -e .[dev]

Upload to PyPi

First you have to build the wheel file:

python3 -m pip wheel .

Then the wheel file can be uploaded to PyPi with:

twine upload --skip-existing python_code_parse-*.whl

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

python_code_parse-0.0.5-py2.py3-none-any.whl (6.6 kB view hashes)

Uploaded Python 2 Python 3

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