jazzband / jazzband/tablib

Initialize a Dataset from plain python dicts

Open
#491 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
4.8k
Forks
617
PR merge metrics
No merged PRs in 30d

Description

I'd like to be able to create a Dataset from plain python dicts. I read through just about everything in the docs and some of the code, and can't seem to find a way to do this directly.

What I'd like to be able to do is something like:
```python
source_data = [
{'column_1': 'value_1A', 'column_2': 'value_2A'},
{'column_1': 'value_1B', 'column_2': 'value_2B'},
]
data = Dataset().load(*source_data)
```
Or maybe:
```python
data = import_set(source_data, format='dict')
```

Current workarounds:
* `json.dumps` the data first before loading
* Register a custom format class
* Separately add headers and row values:
```python
data = DataSet()
data.headers = source_data[0].keys()
data.extend([item.values() for item in source_data])
```

So I guess my questions are:
* Is there currently a better way to do this?
* If not, would you be interested in a PR for this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.