Anyone with a sample code on how to analyze the two main indices directly on netcdf data directly without extracting the values in timeseries will be greatly appreciated.
Have a look at the R climpact2 package available here https://github.com/ARCCSS-extremes/climpact2 .
It requires Tmin, Tmax and Precip, all on daily timesteps, either as a single netcdf file, or 3 separate netcdf files. The main thing is that the netcdf files should comply with the package requirements (e.g. file attributes, units etc). You can modify those things in NCO/CDO if you are familiar with (this is assuming your netcdf is not compliant with the package requirements). All details (including sample script) are provided in the package tutorial on above link. Look at the part on netcdf (you can skip station data). You can create both SPI and SPEI directly as output netcdf files (on 3, 6 and 12 mths. 24, 36 and 48 mths are also possible but with a tweak). It takes a few hours to run on a standard machine depending on the length of your time series, and spatial resolution and extent of gridded data.
You can use R packages of SPEI and SPI. You may need to tweak the code a bit because generally they work on a pre-defined input file format (for e.g. text files of daily rainfall and temperature). If you are not comfortable tweaking the code, and you want to generate SPEI and SPI on netcdf files, use CLIMPACT2 on linux version. It works directly on netcdf file and generates whatever climate index you want to calculate.
Below is the link to get the CLIMPACT2. Use the netcdf one in Linux.