Magento API to create and assign voucher codes programmatically

We have a situation where we need to create voucher codes dynamically and assign it to a set of rules. Since I’m new to magneto programming I’m not aware of using the REST API and all.

Could someone suggest how to do this, Is there an alternative way of accessing it via Python and PostgreSQL?

Also, we need this voucher codes to be sent to the customers on their first order, Do you know what all tables are involved in this?

Awaiting your suggestions. Thanks in advance.