|
1 | 1 | # Python Package Documentation
|
2 | 2 |
|
| 3 | +In addition to a well designed [README.md file](readme-file-best-practices), and a |
| 4 | +[CONTRIBUTING.md file](contributing-file), |
| 5 | +there are several core components of Python package documentation, |
| 6 | +including: |
| 7 | + |
| 8 | +* **User-facing documentation website:** This refers to easy-to-read documentation that helps a user work with your package. This documentation should help users both install and use the functionality of your package. |
| 9 | +* **API documentation:** API documentation is generated from [docstrings](https://pandas.pydata.org/docs/development/contributing_docstring.html) found in your code. Ideally you have docstrings for all user-facing functions, methods and classes in your Python package. |
| 10 | + |
| 11 | + |
3 | 12 |
|
4 | 13 | ```{note}
|
5 | 14 | Examples of documentation that we love:
|
@@ -27,9 +36,44 @@ using language that is less technical.
|
27 | 36 | A few tips to make sure your documentation is accessible include:
|
28 | 37 |
|
29 | 38 | * Whenever possible, define technical terms and jargon.
|
30 |
| -* Consider writing writing instructions for a 12th grade level reader. |
| 39 | +* Consider writing instructions for a high-school level reader. |
31 | 40 | * Include step by step code examples, tutorials or vignettes that support getting started using your package.
|
32 | 41 |
|
| 42 | + |
| 43 | + |
| 44 | +## API's and Docstrings |
| 45 | + |
| 46 | +### What is an API? |
| 47 | + |
| 48 | +API standards for **A**pplied **P**rogramming **I**nterface. When |
| 49 | +discussed in the context of a (Python) package, the API refers to |
| 50 | +the interface and tools that you, as a package user, use in a package. |
| 51 | + |
| 52 | +A simple example of a package API element: |
| 53 | +For instance, a package might have a function called `add_numbers()` |
| 54 | +that adds up a bunch of numbers. To add up numbers, you as the user |
| 55 | +simply call `add_numbers(1,2,3)` and the package function calculates the value and returns `6`. In using the `add_numbers` function, a user is |
| 56 | +using the package's API. |
| 57 | + |
| 58 | + Package API's can consist of functions and/or classes (or object) that provide an easier-to-user interface (the API) for a user. |
| 59 | + |
| 60 | +### What is a docstring and how does it relate to documentation? |
| 61 | +In Python a docstring refers to text in a function, method or class |
| 62 | +that describes what the function does and its inputs, outputs and what it |
| 63 | +returns. |
| 64 | + |
| 65 | +The docstring is thus important for: |
| 66 | + |
| 67 | +* When you, as a user, call `help()` e.g. `help(add_numbers)` in Python, it returns the elements in your docstring to help guide a user towards using the function more effectively. |
| 68 | +* When you build your package's documentation, the docstrings can be also used to automagically create full API documentation that provides a clean view of all functions methods and classes in a package. |
| 69 | + |
| 70 | +```{tip} |
| 71 | +Example API Documentation (Documentation for all functions and classes in a package) |
| 72 | +* [View example high level API documentation for the Verde package. This page lists every function and class in the package along with a brief explanation of what it does](https://www.fatiando.org/verde/latest/api/index.html) |
| 73 | +* [You can further dig down to see what a specific function does within the package by clicking on an API element](https://www.fatiando.org/verde/latest/api/generated/verde.grid_coordinates.html#verde.grid_coordinates) |
| 74 | +``` |
| 75 | + |
| 76 | + |
33 | 77 | ### What tools to use to build your documentation: sphinx
|
34 | 78 |
|
35 | 79 | Most python packages use [sphinx](https://www.sphinx-doc.org/) to build their documentation.
|
|
0 commit comments