Python API¶
ASCII
diagrams language parser and renderer.
print()
and diagram()
.
In addition, Diagram
class may be used to access the low-level API.
- adia.diagram(source, rstrip=True)¶
High level API to generate ASCII diagram.
This function is equivalent to:
Diagram(source).renders()
- adia.print(source, file=None, rstrip=True)¶
High level API to write ASCII diagram into file.
Equivalent to:
Diagram(source).render(file)
Example
import adia source = ''' diagram: Foo sequence: foo -> bar: Hello World! '''' with open('foo.txt', 'w') as outfile: adia.print(source, file=outfile)
- class adia.Diagram(source=None, *args, **kwargs)¶
The main entrypoint of the
adia
package.Diagram
is a collection of actual diagrams such asSequenceDiagram
which implements theInterpreter
abstract class and usesTokenizer
andRenderer
internally to do it’s job.- Parameters
source (str or file-like) – ADia source code to parse.
Note
You may use the
dumps()
method to dump back the diagram instance toADia
source code.- dumps()¶
Serialize back the diagram class into valid
ADia
source code.diagram = Diagram(''' diagram: Foo sequence: foo -> bar: Hello World! ''') print(diagram.dumps())
diagram: Foo sequence: foo -> bar: Hello World!
- parsefile(sourcefile)¶
Parses an
ADia
source file into the current instance.- Parameters
sourcefile (file-like object) – The ADia source file.
- class adia.SequenceDiagram(*args, **kwargs)¶
Represents a sequence diagram.
The
adia.diagram
class creates an instance of this class for each sequence diagram section.