The setup is designed to produce spin-polarized hydrogen and deuterium molecules. Superconducting sextupole magnets with a magnetic induction of 3.4 T near the poles and a field gradient of 320 T/m were used for the spatial separation of molecules with different magnetic moments by spin filtration in an inhomogeneous magnetic field. The choice of the location of the polarized-molecule source elements is justified. Cryogenic pumps are used in the molecular-beam detection chamber in order to obtain an ultrahigh vacuum. At a nozzle temperature of 7 K, the measured flux of spin-polarized hydrogen molecules is 3 x 10(12) molecules/s. For deuterium, the measured flux is lower by more than seven times due to the small magnetic moments.