Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for in-memory diagram generation using BytesIO #999

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rithvikgrandhi
Copy link

This PR introduces the ability to generate diagrams in-memory using a BytesIO object. This is useful for applications that require diagram generation without writing to the filesystem, such as web services or cloud functions.

Changes

  • Added an output_buffer parameter to the Diagram class.
  • Modified the render method to write to the output_buffer if provided.
  • Updated the __exit__ method to handle in-memory diagrams.

Testing

  • Verified that diagrams can be generated and rendered in-memory.
  • Ensured that existing functionality remains unaffected when output_buffer is not used.

Example Usage

from diagrams import Diagram
from io import BytesIO

output_buffer = BytesIO()
with Diagram("Example", output_buffer=output_buffer):
    # Add nodes and edges here
output_buffer.seek(0)
# The diagram is now in the output_buffer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant