Dump headers of parent nested tables
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
Research direction
Start at the tomlkit.dumps(my_dict) entry point and compare its current output with the requested parent-table headers. Determine how the desired formatting could be exposed, then verify the nested apps.test.whatever_1 and apps.test.whatever_2 tables retain their headers and indentation.
Written by the indexing model from the issue text.
Description
Hello,
-
I was trying to convert this python dictionnary
my_dict = { "apps": { "test": { "whatever_1": { "date": "2025-12-16", }, "whatever_2": { "date": "2025-12-16", }, }, }, }...to this TOML output:
[apps] [apps.test] [apps.test.whatever_1] date = "2025-12-16" [apps.test.whatever_2] date = "2025-12-16" -
I first had great hopes with:
print(tomlkit.dumps(my_dict))but that outputs
[apps.test.whatever_1] date = "2025-12-16" [apps.test.whatever_2] date = "2025-12-16" -
With a bit of pain, I eventually manage to get the expected output using:
my_dict_new = tomlkit.document() for category_name, apps in my_dict.items(): cat = tomlkit.table(False) for app_name, app_reports in apps.items(): app = tomlkit.table(False).indent(4) for report_name, report_data in app_reports.items(): rep = tomlkit.table(False).indent(4) for key, val in report_data.items(): rep.add(key, val).indent(4) app.append(report_name, rep) cat.append(app_name, app) my_dict_new.append(category_name, cat) print(tomlkit.dumps(my_dict_new))
As this the reverse scenario from #47 and #107 in which the target output here seemed to be the default .dumps() output at the time, I wonder whether there would be a quicker way to access the old behavior again (i.e. dump headers for parent nested headers) ?
- Dominant language
- Python
- Stars
- 850
- Forks
- 163
- Avg merge
- 13m
- Merged PRs (30d)
- 2
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-poetry/tomlkit
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
python-poetry/tomlkit#546 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
python-poetry/tomlkit#603 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
python-poetry/tomlkit#580 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
python-poetry/tomlkit#577 ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-poetry/tomlkit#574 · 5 comments ·
All issues in python-poetry/tomlkit
Similar issues
-
bug confirmed issue
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
open-webui/open-webui#30750 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
OpenwaterHealth/openmotion-bloodflow-app#604 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 90/100