parsnip-cif

raw JSON →
0.5.0 verified Fri May 01 auth: no python

Minimal library for parsing CIF and mmCIF files in Python. Version 0.5.0, released January 2026. Maintained by the Glotzer Lab. Active development with frequent minor releases.

pip install parsnip-cif
error ModuleNotFoundError: No module named 'parsnip_cif'
cause Attempting to import the module using the package name 'parsnip_cif' instead of the correct module name 'parsnip'.
fix
Replace 'import parsnip_cif' with 'import parsnip' or 'from parsnip import CifFile'.
error FileNotFoundError: [Errno 2] No such file or directory: 'data_test\n_cell_length_a 10.0...'
cause Passing a raw CIF string directly to CifFile without specifying source='string' causes it to treat the string as a file path.
fix
Use CifFile(your_string, source='string') instead.
breaking In version 0.2.0, the primary interface changed to CifFile object. Old code using lower-level parsers may break.
fix Migrate to use CifFile class. See release notes for API changes.
gotcha Import module name is 'parsnip', not 'parsnip_cif'. The PyPI package is 'parsnip-cif' but Python import uses 'parsnip'.
fix Use 'import parsnip' or 'from parsnip import CifFile'.
gotcha When passing a string to CifFile, you must specify source='string' (or another valid source). Otherwise, it may try to open the string as a file path.
fix Always provide source parameter when parsing from a string: CifFile(cif_text, source='string').

Basic parsing of CIF data using CifFile.

from parsnip import CifFile

# Parse from a string
cif_text = """
data_test
_cell_length_a 10.0
_cell_length_b 10.0
_cell_length_c 10.0
"""
cif = CifFile(cif_text, source='string')
print(cif.keys())  # ['_cell_length_a', '_cell_length_b', '_cell_length_c']
print(cif.get('_cell_length_a'))  # '10.0'

# Parse a file (using context manager)
# with open('structure.cif', 'r') as f:
#     cif = CifFile(f)