dbfread
dbfread copied to clipboard
Support for dataclasses?
This is not something we need to support directly in the code, but it would be nice to have a documented way to create dataclasses from records.
I think it should be possible to create dataclasses dynamically be inspecting the DBF object, but perhaps it is best after all to create the dataclass manually.
That's something I'd love to add. How about this API?
@dataclass
class Customer:
id: int
name: str
dbf = dbfread.DBF('customers.dbf', recordfactory=Customer)
This might already work. I haven't tested it.
We could also add support for dynamic dataclasses without adding any new options:
dbf = dbfread.DBF('customers.dbf', recordfactory=dataclass)
This should be fairly easy to implement.
Thanks for the suggestion! If I had created dbfread today I would have made dynamically created dataclasses the default instead of dictionaries.