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

feature request: from_dict() #88

Open
armijnhemel opened this issue May 11, 2022 · 1 comment
Open

feature request: from_dict() #88

armijnhemel opened this issue May 11, 2022 · 1 comment

Comments

@armijnhemel
Copy link

Currently there is a method to_dict() but there is no equivalent from_dict(). It might be useful to have this as well (use case: templating).

@tdruez
Copy link
Collaborator

tdruez commented Jun 27, 2022

@armijnhemel you can already provide a dict to the PackageURL class using the ** unpacking operator:

>>> from packageurl import PackageURL
>>> purl = PackageURL.from_string("pkg:type/namespace/[email protected]")
>>> purl_as_dict = purl.to_dict()
>>> purl_as_dict
{'type': 'type', 'namespace': 'namespace', 'name': 'name', 'version': '1.0', 'qualifiers': None, 'subpath': None}

>>> purl_from_dict = PackageURL(**purl_as_dict)
>>> str(purl_from_dict)
'pkg:type/namespace/[email protected]'

Note that you can use this method with any Python class.

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

No branches or pull requests

2 participants