14.8. TOML Table

  • TOML's table is Python's dict

  • TOML's inline table is Python's dict

14.8.1. Table

Toml:

[user]
firstname = "Alice"
lastname = "Apricot"

This produces the following Python dictionary:

{
    'user': {
        'firstname': 'Alice',
        'lastname': 'Apricot',
    }
}

14.8.2. Inline Table

  • Inline tables provide a more compact syntax for expressing tables.

  • They are especially useful for grouped nested data that can otherwise quickly become verbose.

user = { firstname = "Alice", lastname = "Apricot" }

This is equivalent to:

[user]
firstname = "Alice"
lastname = "Apricot"

They both produce the same Python dictionary:

{
    'user': {
        'firstname': 'Alice',
        'lastname': 'Apricot',
    }
}

14.8.3. Use Case - 1

contact = {
    alice = {
        name = "Alice Apricot",
        email = "alice@example.com",
    },
    bob = {
        name = "Bob Blackthorn",
        email = "bob@example.com",
    },
}

Is equivalent to:

[contact.alice]
name = "Alice Apricot"
email = "alice@example.com"

[contact.bob]
name = "Bob Blackthorn"
email = "bob@example.com"