{"id":16003439,"url":"https://github.com/nhatthm/go-cpy","last_synced_at":"2026-04-11T20:32:33.125Z","repository":{"id":219245333,"uuid":"748553953","full_name":"nhatthm/go-cpy","owner":"nhatthm","description":"Go bindings to the CPython-3 API","archived":false,"fork":false,"pushed_at":"2025-01-06T20:57:12.000Z","size":208,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T09:45:04.317Z","etag":null,"topics":["go","go-python","go-python-c-api","golang","python","python-c-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"sublime-security/cpy3","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nhatthm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-26T08:35:35.000Z","updated_at":"2025-01-06T20:54:33.000Z","dependencies_parsed_at":"2024-03-04T14:04:19.260Z","dependency_job_id":"4a73b2b3-b35a-4b02-a27f-1fd0bb999e32","html_url":"https://github.com/nhatthm/go-cpy","commit_stats":null,"previous_names":["nhatthm/cpy3"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-cpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-cpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-cpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-cpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nhatthm","download_url":"https://codeload.github.com/nhatthm/go-cpy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276096,"owners_count":20912287,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","go-python","go-python-c-api","golang","python","python-c-api"],"created_at":"2024-10-08T10:20:33.679Z","updated_at":"2026-04-11T20:32:33.113Z","avatar_url":"https://github.com/nhatthm.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go bindings for the CPython-3 C-API\n\n\u003e [!IMPORTANT]\n\u003e **Currently supports python-3.12 only.**\n\nThis package provides a ``go`` package named \"python\" under which most of the ``PyXYZ`` functions and macros of the \npublic C-API of CPython have been exposed. Theoretically, you should be able use https://docs.python.org/3/c-api\nand know what to type in your ``go`` program.\n\n## Prerequisites\n\n- `go \u003e= 1.24`\n- `python = 3.12.x`\n\n### MacOS\n  - `brew install python@3.12`\n  - `brew install pkg-config`\n\n### Linux\n\nWe will need `pkg-config` and a working `python3.12` environment to build these bindings. Make sure you have Python \nlibraries and header files installed as well (`python3.12-dev` on Debian, `brew install python@3.12` on macOS, or \n`python3-devel` on Centos for example).\n\nBy default `pkg-config` will look at the `python3` library so if you want to choose a specific version just symlink \n`python-X.Y.pc` to `python3.pc` or use the `PKG_CONFIG_PATH` environment variable.\n\n## Install\n\n```shell\ngo get go.nhat.io/cpy/v3\n```\n\n## API\n\nSome functions mix go code and call to Python function. Those functions will return and `int` and `error` type. The \n`int` represent the Python result code and the `error` represent any issue from the Go layer.\n\nExample:\n\n`func PyRun_AnyFile(filename string)` open `filename` and then call CPython API function \n`int PyRun_AnyFile(FILE *fp, const char *filename)`.\n\nTherefore, its signature is `func PyRun_AnyFile(filename string) (int, error)`, the `int` represent the error code from \nthe CPython `PyRun_AnyFile` function and error will be set if we failed to open `filename`.\n\nIf an error is raise before calling th CPython function `int` default to `-1`.\n\nTake a look at some [examples](examples) and this [tutorial blogpost](https://poweruser.blog/embedding-python-in-go-338c0399f3d5).\n\n## Versioning\n\nWe follow the versioning of the CPython API. The version of this package is `3.12.x` which means it supports the CPython\nAPI version `3.12`. However, the patch version `x` is used to indicate the version of this package, not the CPython API.\nIf you see a version `3.12.7`, it doesn't mean the module only supports CPython API version `3.12.7`, it's just the 7th\ntime we patch to support the CPython API version `3.12`.\n\n## Contributing\n\nContributions are welcome! See [details](CONTRIBUTING.md).  \n\n## Relations\n\n### Relation to `DataDog/go-python3`\n\nThis project is a community maintained successor to [`DataDog/go-python3`](https://github.com/DataDog/go-python3), which will get archived in December 2021.\n\nIf you use the Go package `github.com/DataDog/go-python3` in your code, you can use `go.nhat.io/cpy/v3` as a drop-in replacement. We intend to not introduce breaking changes.\n\n### Relation to `sbinet/go-python`\n\nThis project was inspired by [`sbinet/go-python`](https://github.com/sbinet/go-python) (Go bindings for the CPython-2 C-API).\n\n### Relation to `sublime-security/cpy3`\n\nThis project was a fork of [`sublime-security`](https://github.com/sublime-security) (Go bindings for the CPython-3 C-API) which only supports python 3.10.  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhatthm%2Fgo-cpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhatthm%2Fgo-cpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhatthm%2Fgo-cpy/lists"}