Select to view content in your preferred language

Ship tomli-w with ArcGIS Pro

377
4
12-03-2025 12:52 PM
Status: In Product Plan
TylerT
by
Frequent Contributor

Hello,

ArcGIS Pro removed the toml library from it's default environment, presumably because tomllib is now part of Python's standard library (as of 3.11) and the toml library is older.  Prima facie, this seems fine, except tomllib doesn't have 'write' capabilities.  i.e. We effectively lost toml formatting 'write' capabilities when the toml library was removed, which broke some of our code.  Moving on from the older toml library, one modern recommended writer is the tomli-w library that pairs with Python's standard library tomllib.  Please consider providing a toml writer such as tomli-w.

Ages for reference.

toml (~2013)

tomli-w (~2021)

tomllib (~2022)


Thanks for listening.

Tyler

ArcGIS Pro 3.6

4 Comments
ShaunWalbridge
Status changed to: In Product Plan

Thanks for the suggestion, and sorry we broke some of your code. We did remove toml / tomli as you mentioned because of tomlib being in the standard library, but missed that it drops write support. toml-w is now up on the Esri channel, and we'll work on adding it to the next release of the software.

Cheers, Shaun

HaydenWelch

This is a good proposal, and I think it's good to have a toml writer available in the default environment, but I'm curious what you need writing capabilities for? 

 

https://discuss.python.org/t/revisiting-adding-a-writer-to-tomllib/33030/7

 

There's a reason that a writer hasn't been implemented in the standard lib since the toml spec is meant to be written by and read by humans (unlike standard json which is kinda human readable, but primarily for serializing data).

 

For generating templates why not just use f-strings? If you're serializing data you definitely shouldn't be using toml.

TylerT
by

Hi @HaydenWelch,

Good question. We use TOML for simple configuration files for various report inputs.  While humans can write our config file from scratch, I usually give them a head start by programmatically kicking out a fresh config toml with sensible defaults based on known report requirements.  Ultimately, users open and edit the toml config as they see fit.  Using a library to handle the writing ensures the toml output is always syntactically correct.

Tyler

HaydenWelch

@TylerT Makes total sense, I've always just hard coded a bunch of fstrings for that task since I like leaving comments in my configs. We used to use json and just recently switched to toml so if you think the tomli-w is a better way I might start using it when it's added back.

 

Honestly I feel like it might be worth it to open up a PEP for a tomllib writer that maintains syntax. Tomli-w is only like 300 lines of code, and it seems like the main reason no one is making progress it's because comments matter in toml generation. There's also multiple ways to represent the same structure so you'd need a way for users to be explicit on which style they want.