GithubHelp home page GithubHelp logo

jackokring / cpy3 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sublime-security/cpy3

0.0 0.0 0.0 83 KB

Go bindings to the CPython-3 API

License: MIT License

Python 0.06% C 9.07% Go 90.87%

cpy3's Introduction

Go bindings for the CPython-3 C-API

Currently supports python-3.11 using pkg-config python3-embed.

Might have to build twice as finding built directory?

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.

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 github.com/jackokring/cpy3 as a drop-in replacement. We intend to not introduce breaking changes.
  • If you have unmerged PRs or open issues on DataDog/go-python3, please re-submit them here.

relation to sbinet/go-python

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

Install

Deps

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.

Go get

Then simply go get github.com/jackokring/cpy3

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.

Contributing

Contributions are welcome! See details.

Community

Find us in #go-python on Gophers Slack. (infos | invite)

This project follows the Go Community Code of Conduct.

cpy3's People

Contributors

remicalixte avatar jackokring avatar m-quadra avatar hush-hush avatar christian-korneck avatar rw-access avatar abemedia avatar ivoanjo avatar olivielpeau 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.