pywincffi.core package


pywincffi.core.checks module


Provides functions that are responsible for internal type checks.

pywincffi.core.checks.error_check(function, code=None, expected=None)[source]

Checks the results of a return code against an expected result. If a code is not provided we’ll use ffi.getwinerror() to retrieve the code.

  • function (str) – The Windows API function being called.
  • code (int) – An explicit code to compare against.
  • expected (int) – The code we expect to have as a result of a successful call. This can also be passed pywincffi.core.checks.NON_ZERO if code can be anything but zero.

pywincffi.exceptions.WindowsAPIError – Raised if we receive an unexpected result from a Windows API call

pywincffi.core.checks.input_check(name, value, allowed_types=None, allowed_values=None)[source]

A small wrapper around isinstance(). This is mainly meant to be used inside of other functions to pre-validate input rater than using assertions. It’s better to fail early with bad input so more reasonable error message can be provided instead of from somewhere deep in cffi or Windows.

  • name (str) – The name of the input being checked. This is provided so error messages make more sense and can be attributed to specific input arguments.
  • value – The value we’re performing the type check on.
  • allowed_types – The allowed type or types for value.
  • allowed_values (tuple) – A tuple of allowed values. When provided value must be in this tuple otherwise InputError will be raised.
  • pywincffi.exceptions.InputError – Raised if value is not an instance of allowed_types
  • TypeError – Raised if allowed_values is provided and not a tuple.

pywincffi.core.dist module


Module responsible for building the pywincffi distribution in This module is meant to serve two purposes. The first is to serve as the main means of loading the pywincffi library:

>>> from pywincffi.core import dist
>>> ffi, lib = dist.load()

The second is to facilitate a means of building a static library. This is used by the during the install process to build and install pywincffi as well as a wheel for distribution.


The main function used by pywincffi to load an instance of FFI and the underlying library.

pywincffi.core.logger module


This module contains pywincffi’s logger and functions to retrieve new child loggers.


Returns an instance of logging.Logger as a child of pywincffi’s main logger.

Parameters:name (str) – The name of the child logger to return. For example, if you provide foo for the name the resulting name will be
Raises:ValueError – Raised if name starts with a dot.
Return type:logging.Logger

pywincffi.core.typesbase module

Types Base

Provides the base types on top of which user visible types will be built.

class pywincffi.core.typesbase.CFFICDataWrapper(cdecl, ffi)[source]

Bases: object

Base class for exposing Python types and interfaces to pywincffi users:

  • Wraps a CFFI cdata object in self._cdata.
  • Delegates attribute getting/setting to self._cdata, supporting structs.
  • Delegates item getting/setting to self._cdata, supporting arrays.

Attribute access is not delegated to the wrapped object if the class itself contains such an attribute and that attribute is a descriptor; this is in place to support @property in sub-classes.

  • cdecl (str) – C type specification as used in
  • ffi (cffi.api.FFI) – FFI instance used to create wrapped cdata object.

Module contents

Core Sub-Package

An internal package used by pywincffi for loading the underlying _pywincffi module, handling configuration data, logging and other common tasks. This package also contains the C source and header files.