cymem
Manage calls to calloc/free through Cython
Decision gist · record as of 2026-08-14
Yes, if you write Cython code that allocates C memory. cymem eliminates a common source of bugs (manual deallocation) and is actively maintained with no known vulnerabilities. Install friction is medium due to Cython and compiler requirements, but that's inherent to Cython development, not cymem itself. Not relevant for pure-Python projects.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Cython to be installed and a C compiler available; intended for use in .pyx files, not pure Python.
- Precompiled wheels available for Python 3.9–3.14 across macOS, Linux, Windows, and ARM platforms; medium install friction due to Cython dependency.
- Active maintenance with last commit 2026-03-27 and no known vulnerabilities.
License · maintenance · safety
MIT (permissive) — MIT license (permissive) allows use in commercial and proprietary projects with minimal restrictions; attribution required.
last release 2025-11-14 (273 days) · last repo commit 2026-03-27 · 462 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 21,449,015 downloads/mo, #1,001 on PyPI
Alternatives
Verify before relying
# Install
pip install cymem
# In a .pyx Cython file:
from cymem.cymem cimport Pool
cdef Pool mem = Pool()
cdef int* data = <int*>mem.alloc(10, sizeof(int))
# Memory is automatically freed when Pool is garbage collected- Whether the package is actively used in production by major NLP/ML libraries beyond what can be inferred from download volume.
- Performance overhead of the Pool wrapper compared to direct calloc/free calls.
- Thread-safety guarantees for Python versions prior to 3.13 free-threaded builds.
What it is and what it does
cymem is a Cython library that wraps C's calloc/free functions in a Python-managed Pool object. Instead of manually tracking and freeing allocated memory in Cython code, you attach a Pool to your Cython class and call pool.alloc() for all memory allocations. When the Pool is garbage collected (along with its parent object), all tracked memory is automatically freed—eliminating manual deallocation code and the bugs that come with it.
The library is designed for performance-critical Cython code that works with C-level structs and arrays. It supports custom allocators via WrapMalloc and WrapFree, and as of version 2.0.12, is thread-safe on CPython 3.13+ free-threaded builds. With no runtime dependencies and precompiled wheels for modern Python versions and architectures, it integrates cleanly into existing Cython projects.
Use it for
- Building arrays of C structs in Cython without writing complex __dealloc__ methods.
- Wrapping external C libraries that use private malloc/free functions via custom allocators.
- Managing deeply nested C data structures where manual deallocation is error-prone.
- Reducing memory-leak bugs in performance-critical Cython extensions.
- Simplifying memory lifecycle in Cython classes that hold C-level pointers.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you write Cython code that allocates C memory.
cymem eliminates a common source of bugs (manual deallocation) and is actively maintained with no known vulnerabilities. Install friction is medium due to Cython and compiler requirements, but that's inherent to Cython development, not cymem itself. Not relevant for pure-Python projects.
Install
cymem on PyPI
Before you install
Precompiled wheels available for Python 3.9–3.14 across macOS, Linux, Windows, and ARM platforms; medium install friction due to Cython dependency. Active maintenance with last commit 2026-03-27 and no known vulnerabilities.
Requires Cython to be installed and a C compiler available; intended for use in .pyx files, not pure Python.
License in practice
MIT license (permissive) allows use in commercial and proprietary projects with minimal restrictions; attribution required.
Quickstart
# Install
pip install cymem
# In a .pyx Cython file:
from cymem.cymem cimport Pool
cdef Pool mem = Pool()
cdef int* data = <int*>mem.alloc(10, sizeof(int))
# Memory is automatically freed when Pool is garbage collected
Verify before relying
- Whether the package is actively used in production by major NLP/ML libraries beyond what can be inferred from download volume.
- Performance overhead of the Pool wrapper compared to direct calloc/free calls.
- Thread-safety guarantees for Python versions prior to 3.13 free-threaded builds.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release <3.15,>=3.9 |
| Install friction | Medium. Platform-specific wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 273 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 21,449,015 / month, #1,001 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Environment :: ConsoleIntended Audience :: DevelopersIntended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIX :: LinuxProgramming Language :: CythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Programming Language :: Python :: Free Threading :: 2 - BetaTopic :: Scientific/Engineering |
Evidence: cymem-2.0.13-cp310-cp310-macosx_10_9_x86_64.whl; cymem-2.0.13-cp310-cp310-macosx_11_0_arm64.whl; cymem-2.0.13-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; cymem-2.0.13-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; cymem-2.0.13-cp310-cp310-musllinux_1_2_aarch64.whl; cymem-2.0.13-cp310-cp310-musllinux_1_2_x86_64.whl; cymem-2.0.13-cp310-cp310-win_amd64.whl; cymem-2.0.13-cp310-cp310-win_arm64.whl; cymem-2.0.13-cp311-cp311-macosx_10_9_x86_64.whl; cymem-2.0.13-cp311-cp311-macosx_11_0_arm64.whl; cymem-2.0.13-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; cymem-2.0.13-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; cymem-2.0.13-cp311-cp311-musllinux_1_2_aarch64.whl; cymem-2.0.13-cp311-cp311-musllinux_1_2_x86_64.whl; cymem-2.0.13-cp311-cp311-win_amd64.whl; cymem-2.0.13-cp311-cp311-win_arm64.whl; cymem-2.0.13-cp312-cp312-macosx_10_13_x86_64.whl; cymem-2.0.13-cp312-cp312-macosx_11_0_arm64.whl; cymem-2.0.13-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; cymem-2.0.13-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “cython memory management”
- cymemcymem provides memory-management helpers for Cython that tie…
- cysignalsProvides interrupt and signal handling mechanisms for Cython code,…
- bytesparseProvides a bytearray-like class that stores sparse chunks of data in…
Give your agent the search over MCP, or paste the wish link into any chat.
More Scientific/Engineering packages
NumPy provides an N-dimensional array object and a comprehensive suite of mathematical, linear algebra, Fourier transform, and random number functions for scientific computing in Python.
pandas provides fast, flexible data structures (Series and DataFrame) for loading, cleaning, transforming, and analyzing labeled or relational data in Python.
scipy provides numerical algorithms for mathematics, science, and engineering—including optimization, integration, linear algebra, Fourier transforms, signal and image processing, and ODE solvers—built on numpy arrays.
scikit-learn provides a comprehensive Python library for supervised and unsupervised machine learning, including classification, regression, clustering, dimensionality reduction, and model evaluation tools built on NumPy and SciPy.
Install it if you need to train, evaluate, or deploy supervised or unsupervised learning models.
dill extends Python's pickle module to serialize and deserialize a much wider range of Python objects, including functions, lambdas, classes, and interpreter sessions, to byte streams for storage or network transmission.
Multiprocess is an enhanced fork of Python's standard multiprocessing library that uses dill for better serialization, allowing you to spawn processes with a threading-like API and share complex objects between them.
Install it if you use multiprocessing and encounter pickle serialization limits with lambdas or complex objects.
See also rmm-cu12 · librmm-cu12 · preshed · blis · umf · cython-lint · fastrlock · omnimalloc · backports.weakref · cysignals