Skip to content

Commit 9ea5905

Browse files
committed
Add example and update readme
1 parent a45fd38 commit 9ea5905

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,51 @@
22

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

5+
## Install with pip
6+
7+
```bash
8+
pip install python_code_parse
9+
```
10+
11+
## Usage
12+
13+
Below is the output of running the parser on the example `examples/basic_example.py`:
14+
15+
```python
16+
from python_code_parse import get_all_function_info_from_code, FunctionInfo
17+
from typing import List
18+
19+
with open("examples/basic_example.py", "r") as f:
20+
data = f.read()
21+
22+
function_infos: List[FunctionInfo] = get_all_function_info_from_code(data)
23+
24+
print(function_infos)
25+
26+
"""
27+
[
28+
FunctionInfo(
29+
name='sum',
30+
args=[
31+
FunctionArg(name='a', annotation='int'),
32+
FunctionArg(name='b', annotation='')
33+
],
34+
return_type='None',
35+
line=1
36+
),
37+
FunctionInfo(
38+
name='subtract',
39+
args=[
40+
FunctionArg(name='a', annotation=''),
41+
FunctionArg(name='b', annotation='')
42+
],
43+
return_type='int',
44+
line=4
45+
)
46+
]
47+
"""
48+
```
49+
550
## Setup for Development
651

752
```bash

examples/basic_example.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def sum(a: int, b) -> None:
2+
return a + b
3+
4+
5+
def subtract(a, b) -> int:
6+
return a - b

0 commit comments

Comments
 (0)