https://github.com/ali5h/zig-py-sample
sample python extension in zig
https://github.com/ali5h/zig-py-sample
c-extensions python zig
Last synced: about 1 year ago
JSON representation
sample python extension in zig
- Host: GitHub
- URL: https://github.com/ali5h/zig-py-sample
- Owner: ali5h
- Created: 2022-03-03T01:49:38.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-20T22:16:58.000Z (over 4 years ago)
- Last Synced: 2024-11-14T16:44:48.623Z (over 1 year ago)
- Topics: c-extensions, python, zig
- Language: Zig
- Homepage:
- Size: 80.1 KB
- Stars: 24
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sample Python Extension in Zig
This is tested on Ubuntu with `python3.8` installed.
```
# build the extension
$ zig build
# run zig tests
$ zig build test
# run python tests
$ pytest
```
## logical division of the code
- Pure Zig part is in `src/sum.zig`
- Python ffi is used in `src/ffi.zig` and translated headers are in `src/python3.8.zig`
- The extension is in `src/pysum.zig`
- Sample app to call python code is in `src/callpy.zig`
## python ffi
`python3.8.zig` is generated by running
```
$ zig translate-c /usr/include/python3.8/Python.h -I/usr/include/python3.8 -I /usr/include -I /usr/include/x86_64-linux-gnu/ -D__sched_priority=0 -DNDEBUG > src/python3.8.zig
```