Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/python-api-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build Python API Docs

on:
workflow_dispatch:

permissions: {}

jobs:
build-api-docs:
name: "Build bdkpython API docs"
runs-on: ubuntu-24.04
steps:
- name: "Checkout"
uses: actions/checkout@v4
with:
submodules: recursive
persist-credentials: false
fetch-depth: 0

- name: "Configure Git safe directory"
run: git config --global --add safe.directory /__w/bdk-python/bdk-python

- name: "Install Rust 1.84.1"
uses: actions-rs/toolchain@v1
with:
toolchain: 1.84.1

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: "Generate bdk.py"
env:
PYBIN: ${{ env.pythonLocation }}/bin
run: bash ./scripts/generate-linux.sh

- name: "Install Sphinx and Theme"
run: pip install sphinx sphinx_rtd_theme

- name: "Generate python API Documentation"
run: python ./docs/generate_docs.py

- name: "Build HTML Documentation"
run: python -m sphinx -b html -W --keep-going docs/source docs/_build/html

- name: "Upload API Docs"
uses: actions/upload-artifact@v4
with:
name: artifact-bdkpython-api-docs
path: /home/runner/work/bdk-python/bdk-python/docs/_build/html
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ build/

testing-setup-py-simple-example.py
.localpythonenv/

# API docs
api.rst
_build/
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ pip3 install ./dist/bdkpython-<yourversion>.whl --force-reinstall

python3 -m unittest --verbose
```

## Build HTML API Documentation (Optional)

6. Generate docs
7. Build HTML Documentation

```sh
python3 ./docs/generate_docs.py

python3 -m sphinx -b html -W --keep-going -v docs/source docs/_build/html
```
51 changes: 51 additions & 0 deletions docs/generate_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import re
import subprocess
import shutil

# ----------------
# Generate API RST
# ----------------

# Define the directory where the Python source files are located
src_dir = 'src/bdkpython'
package_root = 'bdkpython'

# Define the output file for the API documentation
output_file = 'docs/source/api.rst'

# Regex pattern to match class definitions
class_pattern = re.compile(r'^class ([A-Za-z][A-Za-z0-9_]*)')

# Store classes with their full module path
public_classes = {}

for root, _, files in os.walk(src_dir):
for file in files:
if file.endswith('.py'):
module_path = os.path.relpath(os.path.join(root, file), src_dir)
module_path = module_path.replace(os.sep, '.').removesuffix('.py')
full_module = f'{package_root}.{module_path}'
with open(os.path.join(root, file), 'r', encoding='utf-8') as f:
for line in f:
match = class_pattern.match(line)
if match:
class_name = match.group(1)
if not class_name.startswith('_'):
fqcn = f'{full_module}.{class_name}'
public_classes[fqcn] = True

# Generate the RST content
rst_content = "API Reference\n============\n\n"

for fqcn in sorted(public_classes.keys()):
rst_content += f".. autoclass:: {fqcn}\n"
rst_content += " :members:\n"
rst_content += " :undoc-members:\n"
rst_content += " :show-inheritance:\n\n"

# Write the RST content to the output file
with open(output_file, 'w') as f:
f.write(rst_content)

print(f"API documentation has been generated in {output_file}")
8 changes: 8 additions & 0 deletions docs/source/_static/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Remove max-width restriction */
.wy-nav-content {
max-width: none !important;
}

.wy-menu-vertical a {
font-size: 1.1em !important;
}
50 changes: 50 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import os
import sys
sys.path.insert(0, os.path.abspath('../../src'))


# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'bdkpython'
copyright = '2025, Bitcoin Dev Kit Developers'
author = 'Bitcoin Dev Kit Developers'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.viewcode',
'sphinx_rtd_theme',
]

templates_path = ['_templates']
exclude_patterns = []

# Suppress docstring formatting warnings due to uniffi bindings
suppress_warnings = [
'docutils'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']

# Register custom CSS
html_css_files = [
'css/custom.css',
]

def setup(app):
app.add_css_file('css/custom.css')
15 changes: 15 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Welcome to bdkpython's documentation!
=====================================

.. toctree::
:maxdepth: 2
:caption: Contents:

api

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ build:
install:
pip3 install dist/bdkpython-*.whl --force-reinstall

[group("Build")]
[doc("Build Sphinx api documentation.")]
api-docs:
python3 -m sphinx -b html -W --keep-going -v docs/source docs/_build/html

[group("Submodule")]
[doc("Initialize bdk-ffi submodule to committed hash.")]
submodule-init:
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pytest==7.1.2
tox==3.25.1
sphinx
sphinx_rtd_theme
Loading