It would be great to include API documentation. The Usage docs are great as a walkthrough, but when you want to go fast ("what is the name for the Field parameter for a constant value?"), API docs provide a faster answer.
Another use case: I want to inspect the __fields__ on a model, and had to read the code to get the attribute name I was looking for.
API docs would be such a great addition to this amazing library! Super useful!
I disagree, documenting everything would be extremely difficult. In the end, the only real source of truth is the code itself. One of the reasons we're all writing python not c is that it's easily readable.
I'd be happy to accept a PR to add info on __fields__ to the model documentation. And many more PRs to extend the documentation in other ways. But I don't think "API docs" as a separate section either auto generated, or hand written are a good idea.
I'm not asking about documenting absolutely everything :) but Field is a good candidate.
The API documentation is usually auto-generated (meaning no inconsistency possible between the code and the doc) and makes it possible for advanced users to go straight to the answers, whereas guides provide a more narrated way of discovering the library.
Here are some good examples of API reference from some major packages:
Here are some good arguments in favor of having an API reference:
See this fairly long discussion on the matter.
I'm strongly opposed to multiple different types of documentation, I think there should be one and only one section of documentation on a feature. That's impossible to achieve entirely, but adding a whole new "api" section to the docs makes it impossible.
The API documentation is usually auto-generated
Is that really true? It's not for python itself, or aiohttp, I wonder if it is for many of the projects you list above. As mentioned on the issue above, it generally doesn't work that well.
There's also no widely used way to auto-generate docs in markdown - maybe that's a strong hint that it's not a populate approach anymore.
Even if they were, the value in docs is in the examples and descriptions. That still has to be written even if it's in docstrings, not md files.
More generally I know the docs could be better, however I don't much enjoy writing docs myself and I get very little help on it from others.
I maintain pydantic for fun and I don't want to spend a significant amount of my free time writing docs, apparently neither does anyone else.
I setup patreon to see if people would who use pydantic would contribute financially, and thereby pay me to do the boring donkey work like docs. It pays me $13/mo. I charge 拢100/hr for development, so that would pay me for 6'30" a month to improve the docs (at the current exchange rate).
There's also the problem of upkeep once the docs are written. I find it hard enough to get people to document the features they add or modify in pull requests. That would only get harder if they had to extend the API docs as well as modify the main documentation.
In short, I think best to submit a PR to add docs for specific things instead of adding another massive section to the docs.
Hey Samuel, thanks for taking the time to answer.
I understand your position. I would still submit that it goes against what most packages are doing, but that would be a somewhat fallacious argument from authority.
I think there are two discussions.
Whether or not pydantic should have an API reference.
I strongly think it should be the case. You don't. In the end, if I don't manage to convince you that it's a useful thing, there's no point in moving further on this ticket and you can close it because you're the repo owner.
Re. your arguments:
autodoc does use the rst format though.If you agree there should an API reference, how to build it
I'd be happy to help! But it's true that the API absolutely needs to be generated, otherwise, it will be a nightmare to maintain them. Another way would be to just include the main parts of the code in the docs (e.g. the Field constructor).
Anyway, in conclusion, just wanted to say that an open source contributor and maintainer myself, I empathize with your feelings re. the time it represents.
Thanks for your input, I get where you're coming from.
Let's see what others think, if lots of people support this I'll think about it more.
Requirements:
There's currently no way to render rst documents within mkdocs, see https://github.com/mkdocs/mkdocs/issues/1817.
So the options are:
If we do have to do this, my preference would be option 4, but even this is a big piece of work that would require a library of its own and ~10 hours of work before we could start using it.
Re: Autogenerating documentation from markdown docstrings, https://github.com/pawamoy/mkdocstrings has sprung up as a mkdocs plugin/extension to do just that, and @pawamoy is currently working on implementing a filter option for more detailed control.
It currently:
# Markdown header
::: pydantic.fields.Field
I can try putting together a PR for documenting things, if you or @charlax have a suggestion of classes to doc, Field et al.
Funny, seeing pydantic and fastapi docs is what made me want to use mkdocs, and then build mkdocstrings :smile:
_1, etc.), you can link back and forth using the classic markdown syntax for references: [title][heading_id] or directly [heading_id][]. Since the generated docs use a heading for every Python object, you can link to them easily, from your markdown pages or from your docstrings. Cross-references will still work even if you move the objects/heading to other pages.UPDATE: mkdocstrings now has a member option, check the docs
I would love to see Field documented. It really confused me that there is no documentation of possible Field args in the docs.
O_o
Sorry I missed it.
I tend to use sphinx for my doc. Mostly prose, but I like generated api doc to exist so I can hyperlink to it. That being said, there is no objects.inv provided for pydantic. That means I need to manually ignore each class or function (using https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-nitpick_ignore) to suppress warnings in the building of my documentation, since my code contains reference to pydantic.
I think that providing objects.inv would be very nice!
FYI there's MyST for Sphinx+Markdown+RST directives now: https://myst-parser.readthedocs.io/.
Most helpful comment
FYI there's MyST for Sphinx+Markdown+RST directives now: https://myst-parser.readthedocs.io/.