Can we write custom python commands in splunk ..
Sure you can:
http://docs.splunk.com/Documentation/Splunk/latest/Search/Aboutcustomsearchcommands
Regards