sphinx-diagrams
This is a rough (incomplete, but working) Sphinx extension for Diagrams. Please refer to the open issue for Sphinx support for the latest up-to-date version when officially supported.
Usage
Install
$ pip3 install sphinx-diagrams
Adding the extension
conf.py
extensions = [
"sphinx_diagrams",
]
Adding the diagram (inline)
The simplest way is to use SphinxDiagram and inline the code in your document.
Consider using an external diagram/python script (see below) as it has much
shorter iteration loop than running sphinx and most likely better supported by
your editor or IDE.
source/index.rst
Diagram - Deployment
====================
.. diagrams::
from diagrams import Cluster
from diagrams.k8s.compute import Deployment
from sphinx_diagrams import SphinxDiagram
with SphinxDiagram(title="GKE"):
with Cluster("GCP Project"):
KubernetesEngine("Primary Cluster")
Adding a diagram (external python code)
Write the code
source/diagrams_infrastructure.py
You can still use SphinxDiagram in your own code. This class handles arguments
like :filename: and visibility (showing the diagram via xdg-open/open) for
you.
from diagrams import Cluster
from diagrams.k8s.compute import Deployment
from sphinx_diagrams import SphinxDiagram
with SphinxDiagram(title="GKE"):
with Cluster("GCP Project"):
KubernetesEngine("Primary Cluster")
Alternatively, you can use Diagram (from diagrams) directly. Note that the
extension will pass two arguments to your diagram script. The first one is the
filename as sys.argv[1] it expects (it needs to match the one outputted by
diagrams) and the value false as sys.argv[2]. The later can be used to
tell your script not to show (open) the generate diagram.
import sys
from diagrams import Diagram, Cluster
from diagrams.gcp.compute import KubernetesEngine
with Diagram("GKE", filename=sys.argv[1], show=sys.argv[2].lower() == 'true'):
with Cluster("GCP Project"):
KubernetesEngine("Primary Cluster")
Referencing the diagram
source/index.rst
Diagram - Deployment
====================
.. diagrams:: diagrams_infrastructure.py
:filename: diagram-deployment.png
If using SphinxDiagram (above) or if the filename of the diagram script is the
same as the output file (e.g.: diagrams_infrastructure.py => diagrams_infrastructure.png) then the :filename: is not necessary.
Diagram - Deployment
====================
.. diagrams:: diagrams_infrastructure.py
Credit
This code is based on sphinx.graphviz.
SPDX-License-Identifier: BSD-2-Clause
Metadata
Release files for sphinx-diagrams 0.4.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 | |
|---|---|---|---|---|
| sphinx-diagrams-0.4.0.tar.gz | 5.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sphinx_diagrams-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.8 kB
Release files / sphinx-diagrams-0.4.0.tar.gz
| Download URL | sphinx-diagrams-0.4.0.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3cf2e0179bdd9ccdb28164fcfcae9b167999a1abe40e159e0c26a225490074d1
|
|
BLAKE2b-256 checksum How to use checksums |
6841e5e874e12f09ea002eee1498cab5fccfd9c6a3348cd3bba82819310d8335
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.3 CPython/2.7.17 Darwin/20.6.0
|
Release files / sphinx_diagrams-0.4.0-py3-none-any.whl
| Download URL | sphinx_diagrams-0.4.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4860291cb04d6361f898d20ba28dca7345f757cdc240caf144c8bf20c73067a0
|
|
BLAKE2b-256 checksum How to use checksums |
8ea322ae4cac618ed0b8d5447dcb67e833bd27a37c958be0540cce5fd34f42e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.3 CPython/2.7.17 Darwin/20.6.0
|
Security for sphinx-diagrams 0.4.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.