MCPcopy Create free account
hub / github.com/goplus/py

github.com/goplus/py @v1.1.00

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.00 ↗ · + Follow
263 symbols 792 edges 33 files 134 documented · 51% 39 cross-repo links updated 2y ago★ 3243 open issues

Browse by type

Functions 233 Types & classes 30
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

py - Golang bindings to the CPython C-API

Build Status

Qiniu Logo

py is Golang bindings to the CPython C-API.

py project's homepage is: https://github.com/qiniu/py

Install

go get github.com/qiniu/py

Example

package main

import (
    "fmt"
    "github.com/qiniu/log"
    "github.com/qiniu/py"
)

// -------------------------------------------------------------------

type FooModule struct {
}

func (r *FooModule) Py_bar(args *py.Tuple) (ret *py.Base, err error) {
    var i int
    var s string
    err = py.Parse(args, &i, &s)
    if err != nil {
        return
    }
    fmt.Println("call foo.bar:", i, s)
    return py.IncNone(), nil
}

func (r *FooModule) Py_bar2(args *py.Tuple) (ret *py.Base, err error) {
    var i int
    var s []string
    err = py.ParseV(args, &i, &s)
    if err != nil {
        return
    }
    fmt.Println("call foo.bar2:", i, s)
    return py.IncNone(), nil
}

// -------------------------------------------------------------------

const pyCode = `

import foo
foo.bar(1, 'Hello')
foo.bar2(1, 'Hello', 'world!')
`

func main() {

    gomod, err := py.NewGoModule("foo", "", new(FooModule))
    if err != nil {
        log.Fatal("NewGoModule failed:", err)
    }
    defer gomod.Decref()

    code, err := py.Compile(pyCode, "", py.FileInput)
    if err != nil {
        log.Fatal("Compile failed:", err)
    }
    defer code.Decref()

    mod, err := py.ExecCodeModule("test", code.Obj())
    if err != nil {
        log.Fatal("ExecCodeModule failed:", err)
    }
    defer mod.Decref()
}

// -------------------------------------------------------------------

Core symbols most depended-on inside this repo

browse all functions →

Shape

Method 129
Function 104
Struct 26
TypeAlias 4

Languages

Go100%
C1%

Modules by API surface

object.go39 symbols
number.go33 symbols
dict.go23 symbols
error.go15 symbols
type.go13 symbols
module.go13 symbols
code.go12 symbols
tuple.go11 symbols
pyutil/call.go10 symbols
goargs.go9 symbols
python.go8 symbols
pyutil/var.go7 symbols

For agents

$ claude mcp add py \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page