In the present study, Malva sylvestris leaf extracts was used as a reducing agent for the synthesis of NiO NPs. They were characterized by FT-IR, XRD, and SEM studies. The synthesis of NiO NPs was monitored by different ratios of nickel nitrate solution and extract by using of SEM technique. The average particle size of NiO NPs was 35 nm which is consistent with the particle size calculated by XRD Scherer equation. Also, the carbon paste electrode modified with NiO NPs (NiO NPs/MCPE) was prepared by mixing of NiO NPs and graphite powder. Then, the electrochemical oxidation of cephalexin at the surface of this electrode was investigated using the cyclic voltammetric and amperometric techniques. The presence of NiO NPs markedly enhances the electrocatalytic activity. Under the selected conditions, the anodic peak current was linearly dependent on the concentration of cephalexin in the range of 2.5–35 µM and 65–1.23 × 103 µM by the amperometric method. The detection limit (S/N = 3) was also estimated to be 1.30 µM. This modified electrode was a simple, rapid and effective sensor that was successfully applied to determine cephalexin in the pharmaceutical samples.