New, thermally stable polyimides and a poly(amide‐imide) containing a 1,3,4‐oxadiazole‐2‐pyridyl pendant group based on 2‐[5‐(3,5‐diaminophenyl)‐1,3,4‐oxadiazole‐2‐yl]pyridine were synthesized. The synthesis and characterization of the model compound 2‐{5‐[(3,5‐bistrimellitimido)phenyl]‐1,3,4‐oxadiazole‐2‐yl}pyridine (DIDA) were also investigated, and DIDA was used in the preparation of the poly(amide‐imide) in an ionic liquid, 1‐butyl‐3‐methylimidazolium bromide, as a polymerization solvent. The polymers were characterized by separating and characterizing the poly(amic acid) intermediates using infrared and elemental analyses. The prepared polymers were soluble in polar and aprotic solvents, such as dimethylformamide, dimethylsulfoxide, N‐methyl‐2‐pyrrolidone and dimethylacetamide. Thermal behaviour of the polymers was studied using thermogravimetric analysis and differential scanning calorimetry. The inherent viscosities of the polyimide and poly(amide‐imide) solutions were in the range 0.34–0.85 dL g−1 (in concentrated sulfuric acid with a concentration of 0.125 g dL−1 at 25 ± 0.5 °C). The removal of Co(II) from aqueous solutions was performed using one of the polyimides. It was found that this polymer had a maximum adsorption capacity and efficiency at pH = 10.0. Copyright © 2012 Society of Chemical Industry