Skip to main content

a tiny package for fast python c++ binding build.

Project description

ccimport

Build Status

a tiny package for fast python c++ binding build.

ccimport 0.2.x support python 3.5. ccimport >= 0.3 support python 3.6-3.9.

Usage

Limitations in Code

  • Function/class with template parameter aren't supported. If you really need to use template, you need to provide all parameters with a default value. The generated code will use func<> to bind your code.

Single File Extension

  • Add CODEAI_EXPORT before your function declaration name. For class, write a static factory member that return a unique_ptr, then add CODEAI_EXPORT_INIT before it.

  • use ccimport.autoimport to build extension.

Multiple File Extension

  • Add CODEAI_EXPORT and/or CODEAI_EXPORT_INIT in header files.

  • Implement functions and classes in source files.

  • use ccimport.autoimport to build extension. you need to add all header files with CODEAI_EXPORT to sources parameter.

Library without pybind

  • Use ccimport.ccimport instead.

API

  • ccimport.autoimport
def autoimport(sources: List[Union[str, Path]], # list of source path, may include headers with 'CODEAI_EXPORT'
               out_path: Union[str, Path], # output path. the name of output file must be a name 
                                           # without platform library prefix and suffix such as `lib-`, '.so'.
               includes: Optional[List[Union[str, Path]]] = None, # include paths
               libpaths: Optional[List[Union[str, Path]]] = None, # library paths
               libraries: Optional[List[str]] = None, # libraries. the name of library must be a name 
                                           # without platform library prefix and suffix such as `lib-`, '.so'.
               export_kw="CODEAI_EXPORT", # use the macro to mark a exported function.
               export_init_kw="CODEAI_EXPORT_INIT", # use the macro to mark a static class factory member.
               compile_options: Optional[List[str]] = None, # compile options.
               link_options: Optional[List[str]] = None, # link options.
               std="c++14", # c++ standard.
               additional_cflags: Optional[Dict[str, List[str]]] = None): # compiler to compile options
    pass
  • ccimport.ccimport
def ccimport(source_paths: List[Union[str, Path]],
             out_path: Union[str, Path],
             includes: Optional[List[Union[str, Path]]] = None,
             libpaths: Optional[List[Union[str, Path]]] = None,
             libraries: Optional[List[str]] = None,
             compile_options: Optional[List[str]] = None,
             link_options: Optional[List[str]] = None,
             source_paths_for_hash: Optional[List[Union[str, Path]]] = None, # if provided, the content of source files will be used
                                                                             # for change detection.
             std="c++14",
             build_ctype=False, # if True, a standard shared library will be built. otherwise a pybind library will be built
             disable_hash=True, # if True, source-content based change detection will be used.
             load_library=True, # if True, the library will be loaded by python or ctypes.CDLL
             additional_cflags: Optional[Dict[str, List[str]]] = None):
    pass

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ccimport-0.3.6.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

ccimport-0.3.6-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

File details

Details for the file ccimport-0.3.6.tar.gz.

File metadata

  • Download URL: ccimport-0.3.6.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for ccimport-0.3.6.tar.gz
Algorithm Hash digest
SHA256 aac802cac00da28ea565776ff6118029402c150ae4314a5e3ef3711fa3d60184
MD5 d3f03fbebced32a6a879ac8d7dcc94d5
BLAKE2b-256 9ef79b8531a23405a4df465c0e2cea6de7b93029511eeffef4cb82202c76fd9a

See more details on using hashes here.

File details

Details for the file ccimport-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: ccimport-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for ccimport-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ab5146bcfa4458dd2187538950aff88ba58bb7b75a04678ccf2d741b443a61e4
MD5 87b1129627fc06526038dbff71047f8c
BLAKE2b-256 03f739cacf6ec0cdb694e01d3f772c4df50934cfe735263c9ef6029082914f59

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page