I want to call some existing code (written in Python) inside my Ethereum smart contract (written in solidity). Is it possible to do that? if so, how can we do it?
The EVM is internally consistent, deterministic and replicable, now and in the future. Its only inputs are signed transactions. These include both messages from users and transaction ordering blocks from miners.
A contract cannot inspect an external source since there is no way to confirm the correctness of such a step in the future. That is, there is no way to use an API to get data because there is no way construct such a thing with assurance that nodes will be able to replicate and confirm the data in the future.
A solution to that problem is an Oracle which is a user that will periodically sign an input. Instead of consulting an external source, the contract consults the Oracle's input. Oracles can be privileged users in a case-specific design or general-purpose relays that consult sources and report with a callback process, e.g. Oraclize.
Oracles push data into contracts, which is opposite flow versus contracts consulting something external.
Hope it helps.