Skip to main content

pytcc is a self-contained python extension for compiling C code (utilizing TCC).

What this extensions sets apart from other TCC extensions is, that no separate TCC installation is required. By simply adding pytcc to your requirements.txt your environment will be setup.

TCC is a full-fledged, blazing fast (up to 9 times faster compilation time than GCC) and extraordinary small (about 300 kb) C99 compiler originally written by Fabrice Bellard and now actively maintained by the community.

This extensions provides a pythonic interface of the API of TCC's tcclib. This library allows not only generating executables and libraries, but also running the generated code in the addressspace of your python process without the need of creating a file on disk.

Installation

The easiest way to install the tool is via pip:

pip install --upgrade pip      # only needed if current pip version < 19.3
pip install pytcc

Alternatively you could build it on your own from source (see chapter "Howto build").

First Steps

To compile a bunch of C files to ank executable and run it (with include/library search path and macros specified):

import pytcc
import subprocess
tcc_setup = pytcc.TCC(include_dirs=['incl'], library_dirs=['libs'], MACRO="value")
exe_binary = tcc_setup.build_to_exe('exename', 'src1.c', 'src2.c')
subprocess.run([str(exe_binary.path)])

If you want to build dynamic library instead of an executable and you want to create it from in-memory source code it would look like:

import pytcc
import ctypes
tcc_setup = pytcc.TCC()
lib_binary = tcc_setup.build_to_lib('libname', pytcc.CCode('''
__attribute__((dllexport)) int func(int p) { 
    return p+1; 
}
'''))
lib = ctypes.CDLL(str(lib_binary.path))
print(lib.func(123))

Alternatively you could build a library in memory and retrieve its symbols:

import pytcc
import ctypes
func_t = ctypes.CFUNCTYPE(None, ctypes.c_int)
tcc_setup = pytcc.TCC()
mem_binary = tcc_setup.build_to_mem('src1.c', 'src2.c')
var_obj = ctypes.c_int.from_address(mem_binary['var'])
func_obj = func_t(mem_binary['func'])
func_obj(var_obj)

Current status

CI Badge

  • Provides tcclib API as pythonic interface
  • Supports all major platforms:
    • Windows x86 and x64
    • macOS x64 (does not support executable/library generation yet and cannot find standard headers by default)
    • linux x64
  • Provide ready to use binary wheels for all supported platforms

Roadmap

  • Make it work on macOS without manually referring to the headerfiles of XCode by adding the darwin headerfiles to the TCC package
  • MAYBE: Extend TCC (and PyTCC) to provide access to AST

Howto Build

To build this extension the following software (apart from python) is required as prerequisites:

  • CMake
  • C Compiler
  • tox [OPTIONAL]

First of all you have to build the TCC binaries by running cmake to create your platform specific project files and then build your project files. In the last step you build the python C-extension as wheel via setup.py.

Linux

>> cmake -B tinycc-bin/linux64
>> cmake --build tinycc-bin/linux64 --config Release
>> pip wheel -w wheels .

macOS

>> cmake -B tinycc-bin/mac64
>> cmake --build tinycc-bin/mac64 --config Release
>> pip wheel -w wheels .

Win32

>> cmake -A Win32 -B tinycc-bin/win32
>> cmake --build tinycc-bin/win32 --config Release
>> pip wheel -w wheels .

Win64

>> cmake -A x64 -B tinycc-bin/win64
>> cmake --build tinycc-bin/win64 --config Release
>> pip wheel -w wheels .

Alternatively you could choose any directory as output for the TCC libraries build by cmake and set the environment variable TCC_BUILD_DIR to the corresponding directory.

If you want to run the unittests the recommended way is running tox after you built the TCC binaries.

Howto debug

To debug pytcc it is recommended to run cmake when the python environment that shall be used for the tests is activated. CMake will then create an additional target: "pytcc". This one can be used for creating the C extention without setup.py. As cmake is supported by most C IDEs you can use the resulting project file to debug the project:

For example on linux the sequence looks like:

>> source .tox/py36/bin/activate  # tox has to be run before this command!
>> cd tinycc-bin/linux64
>> rm -R *                        # necessary as CMake cache has to be reset
>> cmake ../..
>> make pytcc
>> export PYTHONPATH=.
>> python -m pytest ../../tests

Metadata

Release files for pytcc 0.9.27.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pytcc 0.9.27.1.1
File
pytcc-0.9.27.1.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
pytcc-0.9.27.1.1-cp311-cp311-win32.whl CPython 3.11 CPython 3.11 Windows x86-32 Details
pytcc-0.9.27.1.1-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
pytcc-0.9.27.1.1-cp310-cp310-win32.whl CPython 3.10 CPython 3.10 Windows x86-32 Details
pytcc-0.9.27.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
pytcc-0.9.27.1.1-cp310-cp310-macosx_10_15_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.15+ x86-64 Details
pytcc-0.9.27.1.1-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
pytcc-0.9.27.1.1-cp39-cp39-win32.whl CPython 3.9 CPython 3.9 Windows x86-32 Details
pytcc-0.9.27.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
pytcc-0.9.27.1.1-cp39-cp39-macosx_10_15_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.15+ x86-64 Details
pytcc-0.9.27.1.1-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
pytcc-0.9.27.1.1-cp38-cp38-win32.whl CPython 3.8 CPython 3.8 Windows x86-32 Details
pytcc-0.9.27.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
pytcc-0.9.27.1.1-cp38-cp38-macosx_10_15_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.15+ x86-64 Details
pytcc-0.9.27.1.1-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
pytcc-0.9.27.1.1-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details
pytcc-0.9.27.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details
pytcc-0.9.27.1.1-cp37-cp37m-macosx_10_15_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.15+ x86-64 Details
pytcc-0.9.27.1.1-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
pytcc-0.9.27.1.1-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details
pytcc-0.9.27.1.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64 Details
pytcc-0.9.27.1.1-cp36-cp36m-macosx_10_14_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.14+ x86-64 Details

Total release size: 10.2 MB

Release files / pytcc-0.9.27.1.1-cp311-cp311-win_amd64.whl

Download URL pytcc-0.9.27.1.1-cp311-cp311-win_amd64.whl
Size 534.1 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
1950fc084e76d8d0265f42f1e659f0f98eb8f4ef22af68615350be2a61680233
BLAKE2b-256 checksum
How to use checksums
758392313228a255e547fcc00e92f2e221d4b003e3cccb40f9b8c2c8270c267f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp311-cp311-win32.whl

Download URL pytcc-0.9.27.1.1-cp311-cp311-win32.whl
Size 500.4 kB
Tags CPython 3.11 Windows x86-32
SHA-256 checksum
How to use checksums
c000acf09375303ed21d9f2326078e21194536345e335d311e3b9e8cf8d1efe3
BLAKE2b-256 checksum
How to use checksums
9b2efffa13df4c20ce7e85a013e6a7c1bc91826a630b33f45747d90b51c16b05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp310-cp310-win_amd64.whl

Download URL pytcc-0.9.27.1.1-cp310-cp310-win_amd64.whl
Size 534.9 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
13825510638e8d3219ba6c86a71de92a952c88de7cb5400ffff8ad0a868f3bd3
BLAKE2b-256 checksum
How to use checksums
9087b175a1c7a56465c0158d75cc8dcdfcff818c12a7cbd10f1493f73c95cd3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp310-cp310-win32.whl

Download URL pytcc-0.9.27.1.1-cp310-cp310-win32.whl
Size 500.5 kB
Tags CPython 3.10 Windows x86-32
SHA-256 checksum
How to use checksums
98d4a67ea24684db4e53ce6cfbb3fe8c8dcf0978906dabbbb0f4b46cbe905d0e
BLAKE2b-256 checksum
How to use checksums
d8679fd37d8d078ce6ea1fef3628e16d192e5be9689b56bc4259e16ae8bc3ec5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pytcc-0.9.27.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 564.4 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
3b2979b2da090cc15fc387a7de7cec20658802f31a5675a92c051106e414d0ef
BLAKE2b-256 checksum
How to use checksums
cbadad0d3f202b6032e24650e39557bbedd63fac295c6b84c0d8e3f0ea5e195c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp310-cp310-macosx_10_15_x86_64.whl

Download URL pytcc-0.9.27.1.1-cp310-cp310-macosx_10_15_x86_64.whl
Size 236.9 kB
Tags CPython 3.10 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
d348c9c978d51d00ced5ec60e32fe6cd59a510f7741ef83e4f613575de41489b
BLAKE2b-256 checksum
How to use checksums
7c1ec1adbb180456f98d4eeed29bf75e3636e966501f37f07044e3d0dd6fd6c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp39-cp39-win_amd64.whl

Download URL pytcc-0.9.27.1.1-cp39-cp39-win_amd64.whl
Size 536.5 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
52f2c8f17514e72232c141ea2eab236e585e0793538310dd80ae1ad7f12f9616
BLAKE2b-256 checksum
How to use checksums
05aceb41e0103cb07e1c125fa8316adcc3f0eba5304537135e25a9a6011eb1c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp39-cp39-win32.whl

Download URL pytcc-0.9.27.1.1-cp39-cp39-win32.whl
Size 501.7 kB
Tags CPython 3.9 Windows x86-32
SHA-256 checksum
How to use checksums
12956e5299c0190ec9fba5af3b7a92bd2019106709d4bfef9f577e51b3873cb4
BLAKE2b-256 checksum
How to use checksums
ecb0e85811da8a9590cfefcdfe069180178e184ccf61fc841c1a1c4a8d787c58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pytcc-0.9.27.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 568.2 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
baf200cb2d87662a9d796bd2d1dda16299281477034df6480381728f94956b48
BLAKE2b-256 checksum
How to use checksums
c9cc7d9ae8bf373fafedd65196c6b3354a95f1cd76e2206c435baf04317377b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp39-cp39-macosx_10_15_x86_64.whl

Download URL pytcc-0.9.27.1.1-cp39-cp39-macosx_10_15_x86_64.whl
Size 235.0 kB
Tags CPython 3.9 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
be5848adaa586a2c18aa414902f7ccdcfd5a6077f18aa70d7f917ee76e64292e
BLAKE2b-256 checksum
How to use checksums
15833914738982d33b22e89d23428cfdda3b04b1092916db12e23eed2e1881a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp38-cp38-win_amd64.whl

Download URL pytcc-0.9.27.1.1-cp38-cp38-win_amd64.whl
Size 537.0 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
300a16de659e30f1e200ee06be4760822b8ea7cb44a9843aa9fb8ee583cefeb8
BLAKE2b-256 checksum
How to use checksums
1ebc0d5324d9e58a4e7573635b11efb898237b67ae593efea9340840fe677c08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp38-cp38-win32.whl

Download URL pytcc-0.9.27.1.1-cp38-cp38-win32.whl
Size 502.1 kB
Tags CPython 3.8 Windows x86-32
SHA-256 checksum
How to use checksums
0afcf21a0ce389ec62cac09cb64981dd272235f453f678094b337ad24558fa00
BLAKE2b-256 checksum
How to use checksums
0619ebf98ef0cc38f6058ca1056661d1cac2e29c25f0e98478dfa4a3c3a51c57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pytcc-0.9.27.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 577.1 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
d002b248b932be8d3397e15d9966524ceee2227c8eb4f4135bcd0c66b0995d77
BLAKE2b-256 checksum
How to use checksums
6758e79d6b6b9b845b8ed34e71f302095dee7a8d0e0cfd0fb7acad501d996928
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp38-cp38-macosx_10_15_x86_64.whl

Download URL pytcc-0.9.27.1.1-cp38-cp38-macosx_10_15_x86_64.whl
Size 234.0 kB
Tags CPython 3.8 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
eda24e45258fb0ef6389303763d77af44e9a4e410798231b345ab609f21b528b
BLAKE2b-256 checksum
How to use checksums
08a20f37f338aea97cd4b22763b95a03ea83c482087ce7e5f23aec3f377d8517
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp37-cp37m-win_amd64.whl

Download URL pytcc-0.9.27.1.1-cp37-cp37m-win_amd64.whl
Size 534.5 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
df74f614c5f146bc5ce5e44e79955b03e8dc6c368b09f3056494de9e6401c7b5
BLAKE2b-256 checksum
How to use checksums
3b598c6689bd8657fffa0bd544d6a3dccd3cc29381af4de61678f9dca8d6cfb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp37-cp37m-win32.whl

Download URL pytcc-0.9.27.1.1-cp37-cp37m-win32.whl
Size 500.5 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
4ab8a963d434b53ff8fe56624074e41ab334727d829b182c8ffc40781a2e6dc7
BLAKE2b-256 checksum
How to use checksums
673d0fa4211126fac2dec17985bc9b7f597bae04d42c7cfce96bfa414d157a53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pytcc-0.9.27.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 527.5 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9fb79f7fcf84b8c16cc1096f77713c24846656f838bf32236e715de591003d5d
BLAKE2b-256 checksum
How to use checksums
7edbee6ca43f82fe36cdcd5104162490aab3c89ac46aac0d4c57fbc9cc87b9e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp37-cp37m-macosx_10_15_x86_64.whl

Download URL pytcc-0.9.27.1.1-cp37-cp37m-macosx_10_15_x86_64.whl
Size 232.4 kB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
94a8d10cddbaf03ea8e465c3b08ae9a1927a622fda011e4848e2549c7fdd0c5a
BLAKE2b-256 checksum
How to use checksums
9ffd2ce6b9a00792ff49070c22919f29cff0581e3b0fccec7b391f2cfd3365c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp36-cp36m-win_amd64.whl

Download URL pytcc-0.9.27.1.1-cp36-cp36m-win_amd64.whl
Size 540.2 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
175ce635565736220932ebd19b3f305f77bf2c859a2bbdbb99dd8a394bfc25e9
BLAKE2b-256 checksum
How to use checksums
9cddb74a42b083769895f1d92394ecb7011672a99fa8d2dbcbcacbd231bb413f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp36-cp36m-win32.whl

Download URL pytcc-0.9.27.1.1-cp36-cp36m-win32.whl
Size 503.5 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
7a91d11f66b53165a7642ccd83894ae23acf19655b4d2346d19a199629f77d7a
BLAKE2b-256 checksum
How to use checksums
3314a37670e2eaa895fec4fe9df0e509cab308cf7ca2039faeba3221ceb97774
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pytcc-0.9.27.1.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 532.4 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
5308d2001fb7d4bf7adde0112ddbd1f45b7ad2ddca5a70c751bd4604bb7bc16b
BLAKE2b-256 checksum
How to use checksums
4b993d0c1cf9094e02e7daef52e716e08cd67ec54a0c0f5a10229ae66d5f98cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / pytcc-0.9.27.1.1-cp36-cp36m-macosx_10_14_x86_64.whl

Download URL pytcc-0.9.27.1.1-cp36-cp36m-macosx_10_14_x86_64.whl
Size 232.1 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
6c0c4ce73bf14e4bebe81f0aa1c35bee34b9a4659c95288d11b89d01792e8b89
BLAKE2b-256 checksum
How to use checksums
8efc56f4eedca838c6a6174a3297f7745f18241c2b3eb8f96d6184cafa3508a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release history Release notifications | RSS feed

This release

0.9.27.1.1 This release

22 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page