Skip to content

Commit 3942d70

Browse files
bitkarrotthunderbiscuit
authored andcommitted
docs: add python api documentation
1 parent 1db5a7b commit 3942d70

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

bdk-python/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ build/
1515

1616
testing-setup-py-simple-example.py
1717
localenvironment/
18+
venv
19+
env
20+
21+
# API docs
22+
api.rst
23+
index.rst
24+
_build/

bdk-python/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,11 @@ python setup.py --verbose bdist_wheel
4040
```shell
4141
pip install ./dist/bdkpython-<yourversion>.whl
4242
```
43+
44+
## generate the docs
45+
46+
```shell
47+
pip3 install --requirement requirements-dev.txt
48+
python3 scripts/generate_docs.py
49+
sphinx-build -b html -W --keep-going docs/ docs/_build/html
50+
```

bdk-python/docs/conf.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
import sys
3+
sys.path.insert(0, os.path.abspath('..'))
4+
5+
# Configuration file for the Sphinx documentation builder.
6+
project = 'bdkpython'
7+
copyright = '2025, Bitcoin Dev Kit'
8+
author = 'Bitcoin Dev Kit Developers'
9+
10+
# The full version, including alpha/beta/rc tags
11+
release = '1.2.0'
12+
13+
# Add any Sphinx extension module names here, as strings
14+
extensions = [
15+
'sphinx.ext.autodoc',
16+
'sphinx.ext.napoleon',
17+
'sphinx.ext.viewcode',
18+
]
19+
20+
# Add any paths that contain templates here, relative to this directory.
21+
templates_path = ['_templates']
22+
23+
# List of patterns, relative to source directory, that match files and
24+
# directories to ignore when looking for source files.
25+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
26+
27+
# The theme to use for HTML and HTML Help pages.
28+
html_theme = 'sphinx_rtd_theme'
29+
30+
# Add any paths that contain custom static files (such as style sheets)
31+
html_static_path = ['_static']

bdk-python/requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
pytest==7.1.2
22
tox==3.25.1
3+
sphinx
4+
sphinx-rtd-theme

bdk-python/scripts/generate_docs.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import os
2+
import re
3+
4+
# Define the directory where the Python source files are located
5+
src_dir = 'src/bdkpython'
6+
package_root = 'bdkpython'
7+
8+
# Define the output file for the API documentation
9+
output_file = 'docs/api.rst'
10+
11+
# Regex pattern to match class definitions
12+
class_pattern = re.compile(r'^class ([A-Za-z][A-Za-z0-9_]*)')
13+
14+
# Store classes with their full module path
15+
public_classes = {}
16+
17+
for root, _, files in os.walk(src_dir):
18+
for file in files:
19+
if file.endswith('.py'):
20+
module_path = os.path.relpath(os.path.join(root, file), src_dir)
21+
module_path = module_path.replace(os.sep, '.').removesuffix('.py')
22+
full_module = f'{package_root}.{module_path}'
23+
with open(os.path.join(root, file), 'r') as f:
24+
for line in f:
25+
match = class_pattern.match(line)
26+
if match:
27+
class_name = match.group(1)
28+
if not class_name.startswith('_'):
29+
fqcn = f'{full_module}.{class_name}'
30+
public_classes[fqcn] = True
31+
32+
# Generate the RST content
33+
rst_content = "API Reference\n============\n\n"
34+
35+
for fqcn in sorted(public_classes.keys()):
36+
rst_content += f".. autoclass:: {fqcn}\n"
37+
rst_content += " :members:\n"
38+
rst_content += " :undoc-members:\n"
39+
rst_content += " :show-inheritance:\n\n"
40+
41+
# Write the RST content to the output file
42+
with open(output_file, 'w') as f:
43+
f.write(rst_content)
44+
45+
print(f"API documentation has been generated in {output_file}")

0 commit comments

Comments
 (0)