pyMDReport is a Python package made to automatically create .md reports
pyMDReport can be installed via pip through
pip install pyMDReport
Every component in pyMDReport is a child class of pyMDComponent.
pyMDComponents are objects that can be converted in Markdown (md) format.
A pyMDComponent has:
- an identifier ( if not given will use
uuid.uuid4()) - possibly a parent ( a Group, which is also a pyMDComponent )
class pyMDComponent:
parent: Group | None
identifier: str # uuid.uuid4()
anchor: Anchor | None
def __init__( self,
parent: Group | None = None,
identifier: str | None = None,
createAnchor: bool = False,
)if parent is specified, the component is automatically added to the parent's components dict
Every pyMDComponent has 3 main methods
class pyMDComponent:
def MdRows( self ) -> list[str]: pass
def Md( self ) -> str: pass
def Fill( self,
*args: any,
**kwargs: any
): pass- MdRows
The MdRows method is responsible of converting the component in a list of .md rows
def MdRows(self) -> list[str]
Every component has a different MdRows method, since components are converted in md rows in different ways
- Md
The Md method returns the .md rows in a single string
def Md(self) -> str #'\n'.join(self.MdRows())
By default the rows are joined by newline characters
- Fill
The Fill method is responsible of updating the component's data using the params provided
def Fill( self, *args: any, **kwargs: any ): pass
Every component has a different Fill method, since different components contain different data
class ComponentData:
args: tuple
kwargs: dict[str, any]
def __init__( self,
*args,
**kwargs,
): pass
CD = ComponentDataComponentData (alias CD) is just a "storage class" used to group args and kwargs to call a pyMDComponent's Fill method
class Group (pyMDComponent):
components: dict[str, pyMDComponent]
def __init__( self,
*components: pyMDComponent,
parent: Group | Report | None = None,
identifier: str | None = None,
): passChild class of pyMDComponent.
A Group is a component that "contains" other components.
Components are associated to their identifier in Group.components
If any pyMDComponent is given on init, the components dict is automatically updated
Group.components = {
"example" : pyMDComponent,
}A Group has 2 main methods
class Group (pyMDComponent):
def Add( self,
component: pyMDComponent,
componentIdentifier : str | None = None,
): pass
def Fill( self,
componentData: dict[str, ComponentData],
): pass- Add
The Add method is responsible of associating the given component to the group.
def Add( self, component: pyMDComponent, componentIdentifier : str | None = None, )
It adds the component to Group.components
If componentIdentifier is specified, it is used as the key associated to the component
- **Fill** ```python def Fill( self, componentData: dict[str, ComponentData], ) ``` The Group's Fill method is responsible of filling each child component with the correspondent data. *componentData* must be a dict associating the child component *identifier* and the [ComponentData](#componentdata) instance
class Text (pyMDComponent):
text: str
def __init__( self,
text: str | None = None,
): passChild class of pyMDComponent.
A Text is a basic component that represents text.
If any text is given on init, the components dict is automatically updated
A Text has 1 main method
class Text (pyMDComponent):
def Fill( self,
text: str,
): pass- Fill
The Text's Fill method is responsible of storing the given text string.
def Fill( self, text: str, )
class Heading ( Text ):
MAX_HEADING_LEVEL: int = 3
def __init__( self,
headingLevel: int,
): passChild class of Text.
A Heading is a heading text.
headingLevel could be from 1 (highest) to 3 (lowest)
A Heading of level 1 could be created using H1
heading = Heading(1)
# equals
heading = H1()The same thing can be done with H2 and H3
class Quote ( Text ):
passChild class of Text.
A Quote is a quoted text.