### Generate PlantUML Diagram from Command Line Source: https://github.com/dougn/python-plantuml/blob/master/docs/index.md Execute PlantUML from the command line to convert a text file containing a diagram definition into an image file. Ensure the PlantUML module is installed. ```console $ ls sample.txt $ python -m plantuml sample.txt sample.txt: success. $ ls sample.png sample.txt ``` -------------------------------- ### processes() - Get Raw Image Data Source: https://context7.com/dougn/python-plantuml/llms.txt Renders PlantUML text and returns the raw PNG image data as bytes, useful for programmatic image manipulation. ```APIDOC ## processes() - Get Raw Image Data ### Description The `processes()` method renders PlantUML text and returns the raw PNG image data as bytes. This is useful when you need to process or manipulate the image data programmatically. ### Method `processes(uml_text)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from plantuml import PlantUML, PlantUMLHTTPError, PlantUMLConnectionError pl = PlantUML(url='http://www.plantuml.com/plantuml/img/') uml_text = """ title Authentication Sequence Alice->Bob: Authentication Request note right of Bob: Bob thinks about it Bob->Alice: Authentication Response """ try: # Get raw PNG image data image_data = pl.processes(uml_text) # Save to file with open('diagram.png', 'wb') as f: f.write(image_data) print(f"Image saved: {len(image_data)} bytes") except PlantUMLConnectionError as e: print(f"Connection error: {e}") except PlantUMLHTTPError as e: print(f"HTTP error {e.response.status}: {e.response.reason}") ``` ### Response #### Success Response (200) - **image_data** (bytes) - The raw PNG image data of the generated diagram. #### Error Response - **PlantUMLConnectionError**: Raised for network connectivity issues. - **PlantUMLHTTPError**: Raised for HTTP errors from the PlantUML server. ``` -------------------------------- ### PlantUML Diagram Definition Source: https://github.com/dougn/python-plantuml/blob/master/docs/index.md Define a PlantUML diagram using a simple text-based syntax. This example shows an authentication sequence. ```plantuml title Authentication Sequence Alice->Bob: Authentication Request note right of Bob: Bob thinks about it Bob->Alice: Authentication Response ``` -------------------------------- ### Get Raw PlantUML Image Data Source: https://context7.com/dougn/python-plantuml/llms.txt Render PlantUML text and retrieve the raw PNG image data as bytes. Handles potential connection and HTTP errors during the process. Useful for programmatic image manipulation or saving. ```python from plantuml import PlantUML, PlantUMLHTTPError, PlantUMLConnectionError pl = PlantUML(url='http://www.plantuml.com/plantuml/img/') uml_text = """ title Authentication Sequence Alice->Bob: Authentication Request note right of Bob: Bob thinks about it Bob->Alice: Authentication Response """ try: # Get raw PNG image data image_data = pl.processes(uml_text) # Save to file with open('diagram.png', 'wb') as f: f.write(image_data) print(f"Image saved: {len(image_data)} bytes") except PlantUMLConnectionError as e: print(f"Connection error: {e}") except PlantUMLHTTPError as e: print(f"HTTP error {e.response.status}: {e.response.reason}") ``` -------------------------------- ### PlantUML Client Initialization Source: https://context7.com/dougn/python-plantuml/llms.txt Demonstrates how to initialize the PlantUML client with different authentication and configuration options. ```APIDOC ## PlantUML Class - Main Client Interface ### Description The `PlantUML` class provides the primary interface for connecting to a PlantUML server and generating diagrams. It supports optional basic HTTP authentication, form-based authentication, and HTTP proxy configuration through environment variables. ### Method `PlantUML(url, basic_auth=None, form_auth=None, http_opts=None, request_opts=None)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from plantuml import PlantUML # Basic usage with public server pl = PlantUML(url='http://www.plantuml.com/plantuml/img/') # With basic HTTP authentication pl = PlantUML( url='http://private-server.com/plantuml/img/', basic_auth={'username': 'user', 'password': 'secret'} ) # With form-based authentication pl = PlantUML( url='http://private-server.com/plantuml/img/', form_auth={ 'url': 'http://private-server.com/login/', 'body': {'username': 'user', 'password': 'secret'}, 'method': 'POST', # optional, defaults to POST 'headers': {'Content-type': 'application/x-www-form-urlencoded'} # optional } ) # With custom httplib2 options pl = PlantUML( url='http://www.plantuml.com/plantuml/img/', http_opts={'timeout': 30}, request_opts={'follow_redirects': True} ) ``` ``` -------------------------------- ### Initialize PlantUML Client Source: https://context7.com/dougn/python-plantuml/llms.txt Instantiate the PlantUML client with different authentication and configuration options. Supports public and private servers with basic or form-based authentication, and custom httplib2 options. ```python from plantuml import PlantUML # Basic usage with public server pl = PlantUML(url='http://www.plantuml.com/plantuml/img/') # With basic HTTP authentication pl = PlantUML( url='http://private-server.com/plantuml/img/', basic_auth={'username': 'user', 'password': 'secret'} ) # With form-based authentication pl = PlantUML( url='http://private-server.com/plantuml/img/', form_auth={ 'url': 'http://private-server.com/login/', 'body': {'username': 'user', 'password': 'secret'}, 'method': 'POST', # optional, defaults to POST 'headers': {'Content-type': 'application/x-www-form-urlencoded'} # optional } ) # With custom httplib2 options pl = PlantUML( url='http://www.plantuml.com/plantuml/img/', http_opts={'timeout': 30}, request_opts={'follow_redirects': True} ) ``` -------------------------------- ### Run PlantUML via Command Line Interface Source: https://context7.com/dougn/python-plantuml/llms.txt Execute diagram generation directly from the terminal, supporting batch processing, custom output directories, and server configuration. ```bash # Generate PNG from a single file # Input: sample.txt -> Output: sample.png python -m plantuml sample.txt # Process multiple files python -m plantuml diagram1.txt diagram2.txt diagram3.txt # Specify output directory python -m plantuml -o output/ sample.txt # Use a custom PlantUML server python -m plantuml -s http://localhost:8080/plantuml/img/ sample.txt # Show help python -m plantuml --help # usage: plantuml.py [-h] [-o OUT] [-s SERVER] filename [filename ...] # # Generate images from plantuml defined files using plantuml server # # positional arguments: # filename file(s) to generate images from # # optional arguments: # -h, --help show this help message and exit # -o OUT, --out OUT directory to put the files into # -s SERVER, --server SERVER # server to generate from, defaults to plantuml.com ``` -------------------------------- ### Build custom PlantUML URLs Source: https://context7.com/dougn/python-plantuml/llms.txt Construct URLs for different output formats by appending the encoded diagram string to the base server URL. ```python base_url = "http://www.plantuml.com/plantuml" png_url = f"{base_url}/png/{encoded}" svg_url = f"{base_url}/svg/{encoded}" txt_url = f"{base_url}/txt/{encoded}" # ASCII art output print(f"PNG: {png_url}") print(f"SVG: {svg_url}") print(f"TXT: {txt_url}") ``` -------------------------------- ### Process PlantUML Files Source: https://context7.com/dougn/python-plantuml/llms.txt Generate PNG images from PlantUML markup files. Supports specifying output filenames, directories, and error file logging for debugging. Automatically handles output based on input filename if not specified. ```python from plantuml import PlantUML pl = PlantUML(url='http://www.plantuml.com/plantuml/img/') # Basic file processing - outputs to same directory as input # Input: diagram.txt -> Output: diagram.png success = pl.processes_file('diagram.txt') print(f"Generation {'succeeded' if success else 'failed'}") # Specify custom output filename success = pl.processes_file('diagram.txt', outfile='my_diagram.png') # Specify output directory success = pl.processes_file('diagram.txt', directory='output/') # Full control with error file success = pl.processes_file( 'diagram.txt', outfile='output.png', errorfile='error.html', directory='generated/' ) # On success: generated/output.png is created # On error: generated/error.html contains server error response ``` -------------------------------- ### processes_file() - Process PlantUML Files Source: https://context7.com/dougn/python-plantuml/llms.txt Reads PlantUML markup from a file, generates the corresponding PNG image, and handles output filenames and error logging. ```APIDOC ## processes_file() - Process PlantUML Files ### Description The `processes_file()` method reads PlantUML markup from a file and generates the corresponding PNG image. It automatically handles output filenames and can save error pages for debugging. ### Method `processes_file(infile, outfile=None, directory=None, errorfile=None)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from plantuml import PlantUML pl = PlantUML(url='http://www.plantuml.com/plantuml/img/') # Basic file processing - outputs to same directory as input # Input: diagram.txt -> Output: diagram.png success = pl.processes_file('diagram.txt') print(f"Generation {'succeeded' if success else 'failed'}") # Specify custom output filename success = pl.processes_file('diagram.txt', outfile='my_diagram.png') # Specify output directory success = pl.processes_file('diagram.txt', directory='output/') # Full control with error file success = pl.processes_file( 'diagram.txt', outfile='output.png', errorfile='error.html', directory='generated/' ) # On success: generated/output.png is created # On error: generated/error.html contains server error response ``` ### Response #### Success Response (200) - **success** (boolean) - True if the diagram generation was successful, False otherwise. ``` -------------------------------- ### get_url() - Generate Image URL Source: https://context7.com/dougn/python-plantuml/llms.txt Generates the server URL for a PlantUML diagram image, suitable for direct embedding in HTML. ```APIDOC ## get_url() - Generate Image URL ### Description The `get_url()` method returns the server URL for a PlantUML diagram image. This URL can be used directly in HTML IMG tags or for embedding diagrams in web pages without downloading the image. ### Method `get_url(uml_text)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from plantuml import PlantUML pl = PlantUML(url='http://www.plantuml.com/plantuml/img/') uml_text = """ @startuml Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response @enduml """ # Get the URL for the diagram image image_url = pl.get_url(uml_text) print(image_url) # Output: http://www.plantuml.com/plantuml/img/SoWkIImgAStDuNBAJrBGjLDmpCbCJbMmKiX8pSd9vt98pKi1IW80 ``` ### Response #### Success Response (200) - **image_url** (string) - The URL to the generated PlantUML diagram image. ``` -------------------------------- ### PlantUML Authentication Sequence Source: https://github.com/dougn/python-plantuml/blob/master/test/basic.txt Defines an authentication flow between Alice and Bob, including a note for Bob's internal thought process. ```plantuml @startuml Alice->Bob: Authentication Request note right of Bob: Bob thinks about it Bob->Alice: Authentication Response @enduml ``` -------------------------------- ### Handle PlantUML processing exceptions Source: https://context7.com/dougn/python-plantuml/llms.txt Catch specific errors during diagram generation by utilizing the library's custom exception hierarchy. ```python from plantuml import ( PlantUML, PlantUMLError, PlantUMLConnectionError, PlantUMLHTTPError ) pl = PlantUML(url='http://www.plantuml.com/plantuml/img/') uml_text = "@startuml\nAlice -> Bob: Hello\n@enduml" try: image_data = pl.processes(uml_text) print("Success!") except PlantUMLHTTPError as e: # HTTP errors from the server (e.g., 500, 404) print(f"HTTP Error {e.response.status}: {e.response.reason}") print(f"Response content: {e.content}") except PlantUMLConnectionError as e: # Network/connection errors print(f"Connection failed: {e}") except PlantUMLError as e: # Base exception for all PlantUML errors print(f"PlantUML error: {e}") ``` -------------------------------- ### deflate_and_encode() - Encode PlantUML Text Source: https://context7.com/dougn/python-plantuml/llms.txt Compresses and encodes PlantUML text using the custom encoding scheme required by PlantUML servers. ```APIDOC ## deflate_and_encode() - Encode PlantUML Text ### Description The `deflate_and_encode()` function compresses and encodes PlantUML text using the custom encoding scheme required by PlantUML servers. This is useful for building custom URLs or integrating with other tools. ### Method `deflate_and_encode(uml_text)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from plantuml import deflate_and_encode uml_text = """ @startuml class User { +name: String +email: String +login() } @enduml """ # Encode the PlantUML text encoded = deflate_and_encode(uml_text) print(f"Encoded: {encoded}") ``` ### Response #### Success Response (200) - **encoded** (string) - The compressed and encoded PlantUML text. ``` -------------------------------- ### Generate PlantUML Image URL Source: https://context7.com/dougn/python-plantuml/llms.txt Obtain the direct URL for a PlantUML diagram image from PlantUML text. This URL can be used in HTML IMG tags for embedding diagrams. ```python from plantuml import PlantUML pl = PlantUML(url='http://www.plantuml.com/plantuml/img/') uml_text = """ @startuml Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response @enduml """ # Get the URL for the diagram image image_url = pl.get_url(uml_text) print(image_url) # Output: http://www.plantuml.com/plantuml/img/SoWkIImgAStDuNBAJrBGjLDmpCbCJbMmKiX8pSd9vt98pKi1IW80 ``` -------------------------------- ### Encode PlantUML Text Source: https://context7.com/dougn/python-plantuml/llms.txt Compress and encode PlantUML text using the specific scheme required by PlantUML servers. This function is useful for constructing custom URLs or integrating with other tools that need encoded PlantUML markup. ```python from plantuml import deflate_and_encode uml_text = """ @startuml class User { +name: String +email: String +login() } @enduml """ # Encode the PlantUML text encoded = deflate_and_encode(uml_text) print(f"Encoded: {encoded}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.