Remove external modules doc from Python Sphinx

Issue

I’m learning Sphinx and I’m having an issue. I have specified string as a class attribute in my Python code, but the documentation generated by running .\make.bat html shows the same attribute twice, the second with the kivy documentation. I want to only show my docstring documentation, removing the entry added automatically from kivy.

Python code:

from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import StringProperty


class MyApp(App):
    """
    Description.
    
    Attributes
    ----------
    layout : FloatLayout
        the widget returned in the build method
    string : StringProperty
        Some ´string´.
    """
    
    string = StringProperty("")
    
    
    def __init__(self, *args, **kwargs):
        
        self.string = kwargs.get("string", "")
        super().__init__(*args, **kwargs)
        self.layout = FloatLayout()
    
    
    def build(self, *args, **kwargs):
        return self.layout


if __name__ == "__main__":
    MyApp().run()

conf.py file:

# 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

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

import os
import sys

sys.path.insert(0, os.path.abspath('..'))

project = 'Name'
copyright = '2023, Abel'
author = 'Abel'
release = '1.0'

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

extensions = ['sphinx.ext.todo', 'sphinx.ext.viewcode', 'sphinx.ext.autodoc', 'sphinx.ext.napoleon', 'sphinx_mdinclude']

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# -- 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']

index.rst file:

.. Name documentation master file, created by
   sphinx-quickstart on Sat Jun 10 13:14:22 2023.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to Name's documentation!
================================

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



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

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

Rewritten Issue

I’m learning Sphinx and I’m having an issue. When I generate the documentation by running .\make.bat html, the generated documentation about MyApp shows the attribute string twice, the second with the kivy documentation. I want to only show my docstring documentation, removing the entry added automatically from kivy.

To remove the automatically generated documentation from kivy and only show your docstring documentation for the string attribute in Sphinx, you can use the autodoc extension with the autoclass_content configuration option set to "init".

Here’s how you can update your conf.py file:

# 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

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

import os
import sys

sys.path.insert(0, os.path.abspath('..'))

project = 'Name'
copyright = '2023, Abel'
author = 'Abel'
release = '1.0'

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

extensions = ['sphinx.ext.todo', 'sphinx.ext.viewcode', 'sphinx.ext.autodoc', 'sphinx.ext.napoleon', 'sphinx_mdinclude']

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# -- 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']

# -- Options for autodoc extension -------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#configuration

autoclass_content = 'init'

By setting autoclass_content to 'init', Sphinx will only include the docstring documentation for the class attributes and not include the automatically generated documentation from kivy.

After updating the conf.py file, regenerate the documentation by running .\make.bat html to see the updated output.