Package: apimd
apimdA Python API compiler for universal Markdown syntax.Required Python 3.9 and above. (forast.unparsefunction)This parser usingaststandard library to extract the type annotations (without inference) and docstrings, similar to MyPy.
The target modules must be from at least Python 3.0, which is the lowest version withastsupport.A self-compiled example is presented athttps://github.com/KmolYuan/apimd/blob/master/docs/apimd-api.md.InstallInstall by pip:pipinstallapimdFrom Git repository:pipinstall.Command Line InterfaceFollowing syntax are allowed:apimdmodule_name
apimdModule-Name=module_name
apimd"Module Name=module_name"The first is the readable name of the package,
and the second is the name used in import syntax.The output path can be chosen by-dor--diroption, default isdocs.
Multiple modules are supported either.apimdmodule1module2-dout_pathIf you just want to show output, use dry run mode.apimdmodule--dryRulesBasically, this compiler can extract docstrings and annotations from those "public" names:
(PEP484,526)ModulesFunctions & Generators (support async version)Classes and its methodsAccording to PEP 8, "public" means a name can't start with underscore symbol_, except magic methods.
If the public name (other than the magic name) has no docstring, the compiler will issue a warning.
(Naming Conventions)The names must be defined within the scope of module and class,
and supports the use ofifandtrystatements.ConstantsConstants (upper snake case) are no docstring their owned but still listed in module section.
Please mention them in the module docstring.Constant Type InferenceConstant type inference applies to built-in types and containers with built-in types,
such asNone,int,bool,str,tuple,dict[int, str], etc.
You can also annotate them manually.This function also works in class attributes, but doesn't support unpacking.Import InferenceA module should list the objects__all__to prevent other public style names.
In this parser, wildcard import syntax (from ... import *) will be ignored,
which will cause the name from the statement will lose its parent module.
If there has any import statements in the package root__init__.py,
the API can be substituted into a short name, for example, changea.b.ctoa.c.
(Global Variable Names)Generic SelfTo avoid generic self-reference that is not easy to understand,
the compiler introduceSelftype concept fromRust language,
which means the first argument in class should be treated as it and its subclasses.defmethod(self,a:int)->None:...selfareturnSelfintNoneIf a method returns its self, in Python, it can be mark as:classA:_Self=typing.TypeVar('_Self',bound='A')defmethod(self:_Self)->_Self:returnself@classmethoddefmake_method(cls:typing.Type[_Self])->_Self:returncls()selfreturnSelfSelfclsreturntype[Self]SelfThe example shown atself-compiled documentation.Improvement from PEPsIn addition to the basic rules, your documentation will be improved for accepted PEPs,
even it is only implemented in the future version.
(your code still will not be modified)No.Description585Type Hinting Generics In Standard Collections604Allow writing union types as X | YSection LinksSince the converted title id will remove the period symbol,
apimd will insert another HTML anchor id to help you refer to other public names in docstring.
The anchor id is generated from the lowercase full name,
and replace the periods.by hyphens-.
For example,aaa.AAA.bbb_Cccwill becomeaaa-aaa-bbb_ccc.Use--no-linkto prevent this function.Generating Table of ContentsAdd--tocoption to generate the table of contents at the top of the document.
This option will force activate section link option.StubsIf a module has a stub file (.pyi), the stub file will be loaded for annotations once again.
Docstrings should still be written in the module first.
For extensions (.so,.pydor.dylibwith Python version suffix), this tool will try to load the docstrings from module
if.pyfile is not found.