{"id":24737,"library":"trx-python","title":"TRX Python","description":"A community-oriented Python library for reading and writing the TRX (Tractography) file format, designed for efficient storage of streamline tractography data. Current version 0.4.0, requires Python >=3.11, with an active development cadence on GitHub.","status":"active","version":"0.4.0","language":"python","source_language":"en","source_url":"https://github.com/tee-ar-ex/trx-python","tags":["tractography","neuroscience","file-format","streamlines","diffusion-mri"],"install":[{"cmd":"pip install trx-python","lang":"bash","label":"Standard install"}],"dependencies":[{"reason":"Core dependency for array operations","package":"numpy","optional":false},{"reason":"Optional for integration with DIPY tractography workflows","package":"dipy","optional":true}],"imports":[{"note":"TRXFile is in the file submodule, not top-level","wrong":"from trx import TRXFile","symbol":"TRXFile","correct":"from trx.file import TRXFile"},{"note":"MeshContainer is in the mesh submodule","wrong":"from trx import MeshContainer","symbol":"MeshContainer","correct":"from trx.mesh import MeshContainer"}],"quickstart":{"code":"# Create a simple TRX file with two streamlines\nimport numpy as np\nfrom trx.file import TRXFile\n\n# Create two streamlines as arrays of 3D points\nstreamlines = [\n    np.array([[0,0,0], [1,0,0], [2,0,0]], dtype=np.float32),\n    np.array([[0,1,0], [1,1,0], [2,1,0]], dtype=np.float32)\n]\n\n# Write to file\nwith TRXFile('example.trx', mode='wb') as trx:\n    trx.write_streamlines(streamlines)\n\n# Read back\nwith TRXFile('example.trx', mode='rb') as trx:\n    loaded = list(trx.read_streamlines())\n    print(f'Loaded {len(loaded)} streamlines')","lang":"python","description":"Minimal example: create a TRX file with two streamlines and read them back."},"warnings":[{"fix":"Always specify mode='wb' for writing or mode='rb' for reading.","message":"TRXFile now requires explicit binary mode ('wb' or 'rb') when opening. Omitting mode will raise a ValueError in version 0.4.0.","severity":"breaking","affected_versions":">=0.4.0"},{"fix":"Convert data to numpy.float32 before writing: np.array(streamline, dtype=np.float32).","message":"Streamline data must be float32 numpy arrays. Passing float64 or other dtypes may cause silent truncation or errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace read_trx/write_trx calls with 'with TRXFile(...) as trx: trx.read/write_streamlines(...)'.","message":"The function 'read_trx' and 'write_trx' from version 0.2 are deprecated and will be removed. Use TRXFile context manager instead.","severity":"deprecated","affected_versions":">=0.3.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Add mode='rb' or mode='wb' when creating TRXFile.","cause":"Opening TRXFile without mode parameter in 0.4.0.","error":"ValueError: Mode not specified. Use 'rb' for reading or 'wb' for writing."},{"fix":"Use 'from trx.file import TRXFile'.","cause":"Incorrect import: trying to import TRXFile from top-level trx instead of trx.file.","error":"AttributeError: module 'trx' has no attribute 'TRXFile'"},{"fix":"Pass grouping data as a dict with streamline indices as keys: data_per_streamline={...}.","cause":"The 'groups' parameter was removed in 0.4.0. Streamline grouping is now done via the 'data_per_streamline' dictionary.","error":"TypeError: write_streamlines() got an unexpected keyword argument 'groups'"},{"fix":"Ensure the file was written with trx-python 0.4.0+ which forces little-endian. Re-create the file.","cause":"Writing with different endianness or corrupt header; trx-python expects little-endian data.","error":"OSError: [Errno 22] Invalid argument when reading .trx file"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}