Lightweight classes with specified fields in Python

Solution 1:

For anyone finding this question in 2022, the most appropriate Python feature that achieves this is now dataclasses:

from dataclasses import dataclass
from typing import List

@dataclass
class Party:
    guests: List[str]
    location: str

Solution 2:

For a problem you need 50 class definitions for less than five hundred instances . . . in total ? Maybe you should re-consider the problem and find a very different approach ? Tried looking at dictionaries ?

item1 = {'party':'easter', 'guests': ['john', fred','kathy'], 'location':'here'}

Than you need only the standard python dict-class and can easy test field presence, add fields and so on, it has init, repr and eq.

Or provide some more information on the problem.