Skip to content

Add load(s) and dump(s) methods #62

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

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

Conversation

samhaese
Copy link

@samhaese samhaese commented Apr 18, 2025

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))

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