Giter Site home page Giter Site logo

go-cpy's Introduction

Go bindings for the CPython-3 C-API

Important

Currently supports python-3.11 only.

This package provides a go package named "python" under which most of the PyXYZ functions and macros of the public C-API of CPython have been exposed. Theoretically, you should be able use https://docs.python.org/3/c-api and know what to type in your go program.

Prerequisites

  • go >= 1.21
  • python = 3.11.x

MacOS

Linux

We will need pkg-config and a working python3.11 environment to build these bindings. Make sure you have Python libraries and header files installed as well (python3.11-dev on Debian, brew install [email protected] on macOS, or python3-devel on Centos for example).

By default pkg-config will look at the python3 library so if you want to choose a specific version just symlink python-X.Y.pc to python3.pc or use the PKG_CONFIG_PATH environment variable.

Install

go get go.nhat.io/cpy/v3

API

Some functions mix go code and call to Python function. Those functions will return and int and error type. The int represent the Python result code and the error represent any issue from the Go layer.

Example:

func PyRun_AnyFile(filename string) open filename and then call CPython API function int PyRun_AnyFile(FILE *fp, const char *filename).

Therefore, its signature is func PyRun_AnyFile(filename string) (int, error), the int represent the error code from the CPython PyRun_AnyFile function and error will be set if we failed to open filename.

If an error is raise before calling th CPython function int default to -1.

Take a look at some examples and this tutorial blogpost.

Versioning

We follow the versioning of the CPython API. The version of this package is 3.11.x which means it supports the CPython API version 3.11. However, the patch version x is used to indicate the version of this package, not the CPython API. If you see a version 3.11.7, it doesn't mean the module only supports CPython API version 3.11.7, it's just the 7th time we patch to support the CPython API version 3.11.

Contributing

Contributions are welcome! See details.

Relations

Relation to DataDog/go-python3

This project is a community maintained successor to DataDog/go-python3, which will get archived in December 2021.

If 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.

Relation to sbinet/go-python

This project was inspired by sbinet/go-python (Go bindings for the CPython-2 C-API).

Relation to sublime-security/cpy3

This project was a fork of sublime-security (Go bindings for the CPython-3 C-API) which only supports python 3.10.

go-cpy's People

Contributors

remicalixte avatar nhatthm avatar m-quadra avatar hush-hush avatar christian-korneck avatar rw-access avatar abemedia avatar ivoanjo avatar olivielpeau avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.