In Bioconductor there are many packages that can do that, something like topGO or others.
You can look this answer:
A: How can I do GO enrichment analysis for bacteria genome? (biomaRt is not support
-------------------------------
You can get GO terms that are linked to KEGG pathways via the KEGG API.
R/Bioconductor has multiple KEGG-related packages: http://bioconductor.org/help/search/index.html?q=kegg. KEGGSOAP may do what you want.
https://www.biostars.org/p/48776/#48829
-------------------------------
https://github.com/wdecoster/enrichr_cli/blob/master/enrichr-cli.py
https://maayanlab.cloud/Enrichr/enrich
-------------------------------