An efficient first principles approach to calculate X-ray magnetic circular dichroism (XMCD) and X-ray natural circular dichroism (XNCD) is developed and applied in the near edge region at the K-and L1-edges in solids. Computation of circular dichroism requires precise calculations of X-ray absorption spectra (XAS) for circularly polarized light. For the derivation of the XAS cross section, we used a relativistic description of the photon-electron interaction that results in an additional term in the cross-section that couples the electric dipole operator with an operator $mathbf{sigma}cdot (mathbf{epsilon} times mathbf{r})$ that we name spin-position. The numerical method relies on pseudopotentials, on the gauge including projected augmented wave method and on a collinear spin relativistic description of the electronic structure. We apply the method to the calculations of K-edge XMCD spectra of ferromagnetic iron, cobalt and nickel and of I L1-edge XNCD spectra of $alpha$-LiIO3, a compound with broken inversion symmetry. For XMCD spectra we find that, even if the electric dipole term is the dominant one, the electric quadrupole term is not negligible (8% in amplitude in the case of iron). The term coupling the electric dipole operator with the spin-position operator is significant (28% in amplitude in the case of iron). We obtain a sum-rule relating this new term to the spin magnetic moment of the p-states. In $alpha$-LiIO3 we recover the expected angular dependence of the XNCD spectra.