Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MODULE_NAME=python3
MODULE_NAME=python

VENDOR_DIR = vendor

Expand Down
78 changes: 39 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Go high-level bindings for the CPython-3 C-API

[![GitHub Releases](https://img.shields.io/github/v/release/nhatthm/go-python3)](https://github.com/nhatthm/go-python3/releases/latest)
[![Build Status](https://github.com/nhatthm/go-python3/actions/workflows/test.yaml/badge.svg)](https://github.com/nhatthm/go-python3/actions/workflows/test.yaml)
[![codecov](https://codecov.io/gh/nhatthm/go-python3/branch/master/graph/badge.svg?token=eTdAgDE2vR)](https://codecov.io/gh/nhatthm/go-python3)
[![Go Report Card](https://goreportcard.com/badge/go.nhat.io/python3)](https://goreportcard.com/report/go.nhat.io/python3)
[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/go.nhat.io/python3)
[![GitHub Releases](https://img.shields.io/github/v/release/nhatthm/go-python)](https://github.com/nhatthm/go-python/releases/latest)
[![Build Status](https://github.com/nhatthm/go-python/actions/workflows/test.yaml/badge.svg)](https://github.com/nhatthm/go-python/actions/workflows/test.yaml)
[![codecov](https://codecov.io/gh/nhatthm/go-python/branch/master/graph/badge.svg?token=eTdAgDE2vR)](https://codecov.io/gh/nhatthm/go-python)
[![Go Report Card](https://goreportcard.com/badge/go.nhat.io/python)](https://goreportcard.com/report/go.nhat.io/python)
[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/go.nhat.io/python)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)

> [!IMPORTANT]
Expand All @@ -24,69 +24,69 @@ Main goals:
## Install

```bash
go get go.nhat.io/python3
go get go.nhat.io/python/v3
```

## Examples

```go
package python3_test
package main

import (
"fmt"
"fmt"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

func ExampleVersion() {
sys := python3.MustImportModule("sys")
version := sys.GetAttr("version_info")
func main() {
sys := python3.MustImportModule("sys")
version := sys.GetAttr("version_info")

pyMajor := version.GetAttr("major")
defer pyMajor.DecRef()
pyMajor := version.GetAttr("major")
defer pyMajor.DecRef()

pyMinor := version.GetAttr("minor")
defer pyMinor.DecRef()
pyMinor := version.GetAttr("minor")
defer pyMinor.DecRef()

pyReleaseLevel := version.GetAttr("releaselevel")
defer pyReleaseLevel.DecRef()
pyReleaseLevel := version.GetAttr("releaselevel")
defer pyReleaseLevel.DecRef()

major := python3.AsInt(pyMajor)
minor := python3.AsInt(pyMinor)
releaseLevel := python3.AsString(pyReleaseLevel)
major := python3.AsInt(pyMajor)
minor := python3.AsInt(pyMinor)
releaseLevel := python3.AsString(pyReleaseLevel)

fmt.Println("major:", major)
fmt.Println("minor:", minor)
fmt.Println("release level:", releaseLevel)
fmt.Println("major:", major)
fmt.Println("minor:", minor)
fmt.Println("release level:", releaseLevel)

// Output:
// major: 3
// minor: 11
// release level: final
// Output:
// major: 3
// minor: 11
// release level: final
}
```

```go
package python3_test
package main

import (
"fmt"
"fmt"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

func ExampleMath() {
math := python3.MustImportModule("math")
func main() { //nolint: govet
math := python3.MustImportModule("math")

pyResult := math.CallMethodArgs("sqrt", 4)
defer pyResult.DecRef()
pyResult := math.CallMethodArgs("sqrt", 4)
defer pyResult.DecRef()

result := python3.AsFloat64(pyResult)
result := python3.AsFloat64(pyResult)

fmt.Printf("sqrt(4) = %.2f\n", result)
fmt.Printf("sqrt(4) = %.2f\n", result)

// Output:
// sqrt(4) = 2.00
// Output:
// sqrt(4) = 2.00
}
```

Expand Down
2 changes: 1 addition & 1 deletion bool.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3
package python

import "go.nhat.io/cpy3"

Expand Down
4 changes: 2 additions & 2 deletions bool_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package python3_test
package python_test

import (
"testing"

"github.com/stretchr/testify/assert"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

func TestBool(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Package python3 provides a high-level interface to the Python C API.
package python3
// Package python provides a high-level interface to the Python C API.
package python
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3
package python

import (
"go.nhat.io/cpy3"
Expand Down
2 changes: 1 addition & 1 deletion examples/import-modules/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"fmt"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/math/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"fmt"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

func main() { //nolint: govet
Expand Down
2 changes: 1 addition & 1 deletion float.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3
package python

import "go.nhat.io/cpy3"

Expand Down
4 changes: 2 additions & 2 deletions float_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package python3_test
package python_test

import (
"testing"

"github.com/stretchr/testify/assert"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

func TestFloat64(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module go.nhat.io/python3
module go.nhat.io/python/v3

go 1.22

Expand Down
2 changes: 1 addition & 1 deletion import.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3
package python

import (
"go.nhat.io/cpy3"
Expand Down
4 changes: 2 additions & 2 deletions import_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3_test
package python_test

import (
"runtime"
Expand All @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

func TestMustImportModule(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion init.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3
package python

import (
"go.nhat.io/cpy3"
Expand Down
4 changes: 2 additions & 2 deletions init_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package python3_test
package python_test

import (
"os"
"testing"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

// TestMain is the entry point for the test suite.
Expand Down
2 changes: 1 addition & 1 deletion integer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3
package python

import "go.nhat.io/cpy3"

Expand Down
4 changes: 2 additions & 2 deletions integer_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package python3_test
package python_test

import (
"testing"

"github.com/stretchr/testify/assert"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

func TestInt(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3
package python

import (
"reflect"
Expand Down
4 changes: 2 additions & 2 deletions list_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3_test
package python_test

import (
"testing"
Expand All @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"
"go.nhat.io/cpy3"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

func TestList_DecRefNil(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion marshal.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3
package python

import "C"
import (
Expand Down
4 changes: 2 additions & 2 deletions marshal_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3_test
package python_test

import (
"reflect"
Expand All @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

func TestMarshal(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion object.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3
package python

import "go.nhat.io/cpy3"

Expand Down
2 changes: 1 addition & 1 deletion string.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3
package python

import "go.nhat.io/cpy3"

Expand Down
4 changes: 2 additions & 2 deletions string_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package python3_test
package python_test

import (
"testing"

"github.com/stretchr/testify/assert"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

func TestString(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tuple.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3
package python

import (
"reflect"
Expand Down
4 changes: 2 additions & 2 deletions tuple_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package python3_test
package python_test

import (
"testing"

"github.com/stretchr/testify/assert"
"go.nhat.io/cpy3"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

func TestTuple_DecRefNil(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion type.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package python3
package python

// TypeName returns the name of the type of the given object.
func TypeName(o *Object) string {
Expand Down
4 changes: 2 additions & 2 deletions type_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package python3_test
package python_test

import (
"testing"

"github.com/stretchr/testify/assert"

"go.nhat.io/python3"
python3 "go.nhat.io/python/v3"
)

func TestTypeName(t *testing.T) {
Expand Down