Skip to content

Small C++ library to help interface with the ๐Ÿ (Python) API

License

Notifications You must be signed in to change notification settings

ImFstAsFckBoi/snek

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ snek

Small pybind11 inspired C++17 library for interfacing with the Python API. Not very complete or correct. Mostly just for practicing the Python API and C++ metaprogramming.

Usage

It's header only, so just include the snek/snek.hh file. Then use the SNEK_ExportModand snek::ExportFn functions to expose you C++ functions as a Python module. Classes are not implemented yet.

#include "snek/snek.hh"

int mult(int a, int b) {return a * b;}

SNEK_ExportMod(module, "Documentation!...") {
    snek::ExportFn<mult>("mult");
}

Compile as you see fit, for example:

g++ module.cc -o module.so -shared -fPIC -Isnek/include $(pkg-config --cflags python3)

Then you should be able to import and use the module in Python.

>>> from module import mult
>>> mult(3, 2)
6

Install with pip

The nessecary headers can be installed with pip.

pip install "git+https://github.com/ImFstAsFckBoi/snek"

A command to get the include directories, simillar to pkg-config, is included. So now you can compile like this.

g++ module.cc -o module.so -shared -fPIC $(python3 -m snek)

Use with setuptools

To build a an extension using snek with setuptools, use the snek.pkg_config() command to get the includes. Look at testmod/setup.py for a working example.

from setuptools import Extension
from snek import pkg_config

module = Extension(
    name="module",
    sources=["module.cc"],
    include_dirs=pkg_config(),
)

Test

There is a small test that says ALL PASSED! if everything is correct.

pip install . ./testmod && python3 test.py 

About

Small C++ library to help interface with the ๐Ÿ (Python) API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published