Glossary · 2 · Developer SDKs and APIs
Language binding
Also known as: Binding, Language wrapper, Wrapper library
In software engineering, a language binding is glue code that makes a library or API implemented in one programming language usable from another, mapping its functions, types, errors and memory management to the conventions of the target language; bindings are written by hand on a foreign function interface or generated by tools.
- Developer SDK
- Language interoperability
In one sentence
A language binding is glue code that makes a library or API written in one language usable from another, in that language's own conventions.
Example
A vision library written in C++ offers Python bindings, so data scientists call it with NumPy arrays while the image processing runs in the native code.
How it applies
- Developer SDKs: Multi-language SDKs are often one core library with bindings for each supported language. The binding decides whether the SDK feels native: naming, error handling (exceptions vs. return codes), asynchronous calls and how objects are freed.
- Generated bindings: Tools generate bindings from headers or interface files. SWIG connects programs written in C and C++ with a range of high-level languages, including scripting languages such as JavaScript, Perl, PHP, Python, Tcl and Ruby. pybind11 is a lightweight header-only library that exposes C++ types in Python and the other way round, mainly to create Python bindings of existing C++ code. Automatic code generation from an interface definition is the same idea for remote APIs.
- Hardware SDKs: Device and accelerator kits implement in C or C++ for speed and hardware access and offer bindings for Python, Java or C#; the binding is how most users meet the hardware.
- Platform SDKs: Host applications with a native core expose their extension API through bindings to a scripting language, so that extensions do not need to be compiled.
- Documentation: Each binding needs its own reference in its language, with notes where it differs from the core (missing functions, different defaults, thread safety). Samples should be tested per binding, because a binding can lag behind the core.
Language binding vs. client library
A language binding wraps a library that runs in the same process. A client library wraps a remote API reached over a network. Some SDKs are both: a client library implemented once in a native core and exposed through bindings to several languages.
External references
- SWIG project: SWIG
- pybind11: pybind11 documentation