I'm writing a Python library, and trying to decide on a specific, top level, API. Basically is it nicer to pass a list of objects or just pass a dict?
method(credentials=[
Credential(name="something", value="something else")
])
method(credentials={
something: "something else"
})
Option 1 is more verbose, but also more explicit. It's harder to make errors with, and makes those errors easier to catch. Option 2 is just data, which is both less verbose and also easier to string together from external sources. Thoughts?
I'd say that it depends on how complex will
credentials
be. If it's justkey: value
, where value is scalar (or close enough), yeah, sure, dict is fine. Maybe even**kwargs
. If the values might be very complex, or there might be lots of different keys with different meanings, than I'd say objects are better.