PyDBML icon indicating copy to clipboard operation
PyDBML copied to clipboard

Add load(s) and dump(s) methods

Open samhaese opened this issue 8 months ago • 0 comments

When I'm working with markup files in Python I usually use one of these packages:

I noticed that all of them have pretty much the same API:

  • dump writes a file
  • dumps returns a string
  • load parses a file
  • loads parses a string

I added that API to your package because it could make it easier for people to adopt it. I would understand if you rejected this change.

Example:

import pydbml

with open('test_file.dbml', 'r') as f:
    db = pydbml.load(f)

with open('test_save.dbml', 'w') as f:
    pydbml.dump(db)

s = """Table users {
    id integer
    user varchar
    role varchar
    created_at timestamp
}"""

db2 = pydbml.loads(s)

print(pydbml.dumps(db))

samhaese avatar Apr 18 '25 22:04 samhaese