I have two Python files that I want to prevent anyone from executing unless it's from the server itself. The files implement a function that increases an amount of money to a user. What I need is to make this file not public to the web, so that if someone tries to call this file, the file would refuse this request, unless the call is from the server. 
Does anyone know how I can do this? My first idea was to check for the IP address but a lot of people can spoof their IP.
Example
Let's say I have this file: function.py, a function in this file will accept a new amount of money and increase the appropriate balance in the database. 
When someone tries to post data to this file, and this person is outside the server (lets say from 244.23.23.0) the file will be in-accessible. Whereas, calling the function from the server itself will be accepted. 
So files can access other files on the server, but external users cannot, with the result that no one can execute this file unless it's called from the server.
This is really important to me, because it's related to real money. Also, the money will come from PayPal IPN. And actually, if there was a way to prevent access unless it was coming from PayPal, that would be an amazing way to secure the app.
OK, as far as what I have tried: 

Put the database in a cloud SQL using Google [https://developers.google.com/cloud-sql/]
Try to check the IP of the incoming request, in the file

Thanks for any and all help.
.htaccess, chmod or you could use a key defined by yourself... You have several possibilies.
Edit: Anyway, if the file only contains a function. Nobody can use it from an external http request, unless you actually call it in this file: function();
Restrict execution of Python files only to server (prevent access from browser)