mkdocs-apicall-plugin
Auto-generate code samples to make API calls
Installation
pip install mkdocs-apicall-plugin
This plugin works with the material theme and is built on top of the tabbed and superfenced extensions from PyMdown. Enable the extensions and the plugin in your mkdocs.yml:
theme:
name: material
markdown_extensions:
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
plugins:
- apicall
Syntax
The syntax is given below. Basically it may look like a classical HTTP request message.
@@@ <METHOD> <PATH> [<PAYLOAD>]
[<HEADER-KEY>: <HEADER-VALUE>]
[<HEADER-KEY>: <HEADER-VALUE>]
The method and the paths are both mandatory. One can append a payload (only a json for the moment) to the first line. The following lines are extra indented HTTP headers.
Configuration
The plugin supports few options:
line_length [int] is the maximum length of a line of code before splitting into several lines.
icons [bool] activates language icons. You must add the following extensions:
markdown_extensions:
# ...
- attr_list
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
languages [list] filters the languages to display (show all by default). The order is also taken into account. The term language is clearly a misuse as it rather refers to a way to make the API call (so we may have curl, wget along with typescript for example). Currently 3 languages are supported: curl, python and javascript.
As an example you may have:
plugins:
- apicall:
line_length: 90
icons: true
languages:
- curl
- python
- javascript
You can also pass extra configuration to a language by adding some sub-keys:
plugins:
- apicall:
line_length: 90
icons: true
languages:
- curl:
options:
- "-s"
- python
- javascript
Currently only curl supports the options sub-key to insert some CLI options.
Contributing
Obviously, we need to dev more languages and increase the number of features: HTTP options, language options, code formatting...
How?
Open an issue, we may possibly discuss about the requested feature and if we are OK, you can create a branch and submit PR.
Developing a new language
To add a new language, you have to create a new source code file inside the mkdocs_apicall_plugin/ folder.
Basically a language looks as follows:
from .abstract import APICall
class NewAPICall(APICall):
# [unique] name of the language. This is what is displayed
# in the tabs
name: str = "new"
# material mkdocs icons (see https://squidfunk.github.io/mkdocs-material/reference/icons-emojis/)
icon: str = ":material-web:"
# Pygments language for syntax highlighting
# (see https://pygments.org/languages/)
lang: str = "shell"
# Indentation when the call is wrapped into several lines
# This is just for internal use (so it depends on how you
# code the language)
indent: str = " " * 5
def render_code(self) -> str:
"""Single function to implement. It must return the raw
string that will be encapsulated in code blocks and tabs.
"""
# TODO
So, you must implement a subclass of APICall and notably the render_code method. This method returns only the code as string,
as you may write in your favorite editor.
You have access to several attributes:
| Attribute | Type | Details |
|---|---|---|
_method |
abstract.HttpMethod |
Like GET or POST. This is always uppercase |
_url |
str |
API endpoint to reach |
_headers |
Dict[str, Any] |
HTTP headers |
_body |
str |
Raw body as string (as it is written in the API call within the markdown source file) |
_max_line_length |
int |
Maximum line length desired |
_print_icon |
bool |
Whether the icon will be printed (normally it does have impact on your dev) |
_language_config |
dict |
Language specific configuration |
Metadata
Release files for mkdocs-apicall-plugin 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mkdocs_apicall_plugin-0.3.0.tar.gz | 377.6 kB | With provenance | Details for mkdocs_apicall_plugin-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mkdocs_apicall_plugin-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for mkdocs_apicall_plugin-0.3.0-py3-none-any.whl |
Total release size: 390.6 kB
Release files / mkdocs_apicall_plugin-0.3.0.tar.gz
| Download URL | mkdocs_apicall_plugin-0.3.0.tar.gz |
|---|---|
| Size | 377.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
29df9a8833675264ea006dc6f4acc662b20492dbe36396815c8e9f7284082c83
|
|
BLAKE2b-256 checksum How to use checksums |
387b25aacbd87d16158d6cc930f0528593396fa9bde2be44e7e3a8c189a24330
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 13, 2025.
Transparency logRelease files / mkdocs_apicall_plugin-0.3.0-py3-none-any.whl
| Download URL | mkdocs_apicall_plugin-0.3.0-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f9e4a9b77e7fa7d5b159456ae8cd1a2bbbd0d74efbcb5d00fe0b18e317290460
|
|
BLAKE2b-256 checksum How to use checksums |
2c78d0b9230ac6e4358d68e222ac5803efa6ba7df22b0c4598106715632edd86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 13, 2025.
Transparency logSecurity for mkdocs-apicall-plugin 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for mkdocs_apicall_plugin-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 13, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.