© 2019 American Physical Society. We extend the theory of stochastic thermodynamics in three directions: (i) instead of a continuously monitored system we consider measurements only at an arbitrary set of discrete times, (ii) we allow for imperfect measurements and incomplete information in the description, and (iii) we treat arbitrary manipulations (e.g., feedback control operations) which are allowed to depend on the entire measurement record. For this purpose we define for a driven system in contact with a single heat bath the four key thermodynamic quantities - internal energy, heat, work, and entropy - along a single "trajectory" for a causal model. The first law at the trajectory level and the second law on average is verified. We highlight the special case of Bayesian or "bare" measurements (incomplete information, but no average disturbance) which allows us to compare our theory with the literature and to derive a general inequality for the estimated free energy difference in Jarzynski-type experiments. An analysis of a recent Maxwell demon experiment using real-time feedback control is also given. As a mathematical tool, we prove a classical version of Stinespring's dilation theorem, which might be of independent interest.