In this study, a newly-designed diamine (DA) containing pyridine and carbazole groups was synthesized and the relevant polyamides (PAs) and polyimides (PIs) were prepared by polymerization reaction between the DA monomer and terephthalic acid, adipic acid, and pyromellitic dianhydride. In addition, polymer nanocomposites were prepared through a combination of the synthesized polymers with modified magnetite iron oxide nanoparticles. The synthesized compounds were fully characterized by hydrogen nuclear magnetic resonance (1HNMR), fourier-transform infrared (FTIR), field emitting scanning electron microscopy (FESEM), energy dispersive X-Ray (EDX), Transmission electron microscopy (TEM), Differential scanning calorimetry (DSC) and Thermogravimetric analysis (TGA) analyses. All of the synthesized properties of compounds such as thermal stability, viscosity, elimination capability of heavy metals ions adsorption, and antibacterial activity were investigated. Polyamides and PI showed good solubility in aprotic solvents and the viscosity was in the range of 0.72–0.89 dL/g. Also, the glass-transition temperature (Tg) of synthetic polymers was in the range of 214– 273°C and 10% weight loss temperatures (T10%) for the synthesized compounds were in the temperature range of 280– 492°C in N2, and the percentage of residual ash between 61 and 74%. The adsorption rate of Hg2+, Co2+, Pb2+, Cr2+, and Cd2+ metal ions by PA containing terephthalic acid (PAT) and its nanocomposite (NCPAT) showed that nanocomposite has a better performance compared to PAT. The highest and lowest removal efficiency was related to Hg2+ and Pb2+ ion, respectively. Finally, antibacterial test results against Gram-positive and Gram-negative bacteria showed favorable inhibitory effects of all the synthesized polymers