To create Policies programmatically, yu will need to use the Dashboard REST API which has a policies endpoint.
If you are running Tyk and the Dashboard then this will be the only way to create and load policies.
To use file-based policy loading, then you'll need to not use the dashboard at all (or at least, not to set up and manage policies).
Policies are added to the policie folder which is defined in the Tyk.conf file.
The relevant details are in the docs for he configuration file here:
The relevant config we're using is:
Set this value to file to look on the file system for a definition file, set to service to use the dashboard service. Note the option for mongo has now been removed.
You'll need to use the dashboard RESt API if you want to export your definitions into a file format.
The policy file format is like the example shows, one JSON object with all the relevant policies as sub documents (see https://github.com/TykTechnologies/tyk/blob/master/policies/policies.json)
Hope that helps.