Heat oven to 190C/fan 170C/gas 5. Slide a baking sheet in to heat. Roll the pastry out enough to line a deep 20cm flan tin or a shallow 23cm one. Chill for 10 mins.
Put a few balls of crumpled foil in the base of the pastry case and bake on the baking sheet for 10 mins. Remove the foil and bake for 5 mins more, until light golden.
Meanwhile, cook the onions in the oil until starting to soften, then add thyme, pepper, and salt if you want to. Cook slowly for about 15 mins until the onions are soft and tinged brown.
Beat the eggs, beat in the milk and half the cheese and some pepper. Spread the onions over the flan case and pour in the egg mix. Sprinkle the remaining cheese on top and bake the tart on the baking sheet for 30-40 mins until the filling is firm and golden, and the pastry crisp. Serve warm or cold.