{"id":16003536,"url":"https://github.com/nhatthm/go-python","last_synced_at":"2025-10-17T09:38:44.927Z","repository":{"id":222373998,"uuid":"755798297","full_name":"nhatthm/go-python","owner":"nhatthm","description":"Go high-level bindings for the CPython-3 C-API","archived":false,"fork":false,"pushed_at":"2024-11-25T19:39:28.000Z","size":57,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-30T15:23:45.071Z","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":null,"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":null,"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}},"created_at":"2024-02-11T04:51:56.000Z","updated_at":"2024-11-11T03:18:42.000Z","dependencies_parsed_at":"2024-03-02T11:25:16.727Z","dependency_job_id":"a5b5c3d5-9724-4c42-a87f-2071261f8173","html_url":"https://github.com/nhatthm/go-python","commit_stats":null,"previous_names":["nhatthm/go-python3","nhatthm/go-python"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nhatthm","download_url":"https://codeload.github.com/nhatthm/go-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230227182,"owners_count":18193268,"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:21:09.827Z","updated_at":"2025-10-17T09:38:39.897Z","avatar_url":"https://github.com/nhatthm.png","language":"Go","funding_links":["https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY"],"categories":[],"sub_categories":[],"readme":"# Go high-level bindings for the CPython-3 C-API\n\n[![GitHub Releases](https://img.shields.io/github/v/release/nhatthm/go-python)](https://github.com/nhatthm/go-python/releases/latest)\n[![Build Status](https://github.com/nhatthm/go-python/actions/workflows/test.yaml/badge.svg)](https://github.com/nhatthm/go-python/actions/workflows/test.yaml)\n[![codecov](https://codecov.io/gh/nhatthm/go-python/branch/master/graph/badge.svg?token=eTdAgDE2vR)](https://codecov.io/gh/nhatthm/go-python)\n[![Go Report Card](https://goreportcard.com/badge/go.nhat.io/python/v3)](https://goreportcard.com/report/go.nhat.io/python/v3)\n[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/go.nhat.io/python/v3)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)\n\n\u003e [!IMPORTANT]\n\u003e **Currently supports python-3.12 only.**\n\nThe package provides a higher level for interacting with Python-3 C-API without directly using the `PyObject`.\n\nMain goals:\n- Provide generic a `Object` that interact with Golang types.\n- Automatically marshal and unmarshal Golang types to Python types.\n\n## Prerequisites\n\n- `Go \u003e= 1.24`\n- `Python = 3.12`\n\n## Install\n\n```bash\ngo get go.nhat.io/python/v3\n```\n\n## Examples\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    python3 \"go.nhat.io/python/v3\"\n)\n\nfunc main() {\n    sys := python3.MustImportModule(\"sys\")\n    version := sys.GetAttr(\"version_info\")\n\n    pyMajor := version.GetAttr(\"major\")\n    defer pyMajor.DecRef()\n\n    pyMinor := version.GetAttr(\"minor\")\n    defer pyMinor.DecRef()\n\n    pyReleaseLevel := version.GetAttr(\"releaselevel\")\n    defer pyReleaseLevel.DecRef()\n\n    major := python3.AsInt(pyMajor)\n    minor := python3.AsInt(pyMinor)\n    releaseLevel := python3.AsString(pyReleaseLevel)\n\n    fmt.Println(\"major:\", major)\n    fmt.Println(\"minor:\", minor)\n    fmt.Println(\"release level:\", releaseLevel)\n\n    // Output:\n    // major: 3\n    // minor: 11\n    // release level: final\n}\n```\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    python3 \"go.nhat.io/python/v3\"\n)\n\nfunc main() { //nolint: govet\n    math := python3.MustImportModule(\"math\")\n\n    pyResult := math.CallMethodArgs(\"sqrt\", 4)\n    defer pyResult.DecRef()\n\n    result := python3.AsFloat64(pyResult)\n\n    fmt.Printf(\"sqrt(4) = %.2f\\n\", result)\n\n    // Output:\n    // sqrt(4) = 2.00\n}\n```\n\n## Donation\n\nIf this project help you reduce time to develop, you can give me a cup of coffee :)\n\n### Paypal donation\n\n[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;or scan this\n\n\u003cimg src=\"https://user-images.githubusercontent.com/1154587/113494222-ad8cb200-94e6-11eb-9ef3-eb883ada222a.png\" width=\"147px\" /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhatthm%2Fgo-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhatthm%2Fgo-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhatthm%2Fgo-python/lists"}