{"id":46834,"library":"xraydb","title":"XrayDB","description":"XrayDB provides reference data for X-ray interactions with matter, including atomic scattering factors, X-ray absorption cross-sections, fluorescence yields, and more.  Version 4.5.8 supports Python >=3.9.  Release cadence is irregular, with occasional minor updates.","status":"active","version":"4.5.8","language":"python","source_language":"en","source_url":"https://github.com/xraypy/XrayDB","tags":["x-ray","scattering","absorption","atomic data","synchrotron"],"install":[{"cmd":"pip install xraydb","lang":"bash","label":"pip install"}],"dependencies":[],"imports":[{"note":"Main class used for querying X-ray data.","wrong":"","symbol":"XrayDB","correct":"from xraydb import XrayDB"},{"note":"Returns anomalous scattering factors f1 and f2 given element and energy.","wrong":"","symbol":"f1_energies","correct":"from xraydb import f1_energies"},{"note":"Returns atomic density element.","wrong":"","symbol":"atomic_density","correct":"from xraydb import atomic_density"}],"quickstart":{"code":"import os\nfrom xraydb import XrayDB\n\n# Use an API key if required (currently no key needed for local database)\ndb = XrayDB(cache_dir=os.environ.get('XRAYDB_CACHE', '/tmp/xraydb_cache'))\n\n# Get anomalous scattering factors for iron at 7 keV\nenergy = 7000  # eV\nf1, f2 = db.f1_energies('Fe', energy)\nprint(f\"f1 = {f1:.3f}, f2 = {f2:.3f}\")\n\n# Get x-ray absorption cross-section for copper at 10 keV\nmu = db.mu('Cu', 10000)\nprint(f\"mu = {mu:.5e} cm^2/g\")","lang":"python","description":"Basic usage of XrayDB to fetch anomalous scattering factors and absorption cross-sections."},"warnings":[{"fix":"None (expected behavior).  Alternatively, use system database by setting environment variables or installing separately.","message":"The database is bundled with the package; a large download (~100 MB) occurs on first import or use.  Ensure sufficient disk space and internet connection.","severity":"gotcha","affected_versions":"all"},{"fix":"Delete the cache directory: rm -rf ~/.xraydb","message":"The database download URL changed in version 4.5.0; older cached databases may cause errors until deleted.  If you see \"Database version mismatch\" after upgrading, remove the cache directory (default ~/.xraydb).","severity":"gotcha","affected_versions":">=4.5.0, <4.6.0"},{"fix":"Use from xraydb import XrayDB; db = XrayDB(); db.mu('Fe', 7000) instead.","message":"The function `get_xraydata` was removed in version 4.0.0 without deprecation.  Use `XrayDB` class methods instead.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Set an alternative cache directory with XRAYDB_CACHE environment variable or pass cache_dir to XrayDB().","message":"The database file is large (over 100 MB) and may cause slow first-time imports.  On low-storage systems, import can fail with insufficient space.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'3.9':32 '4.5.8':29 'absorpt':20,45 'atom':14,46 'cadenc':34 'cross':22 'cross-sect':21 'data':5,47 'factor':16 'fluoresc':24 'includ':13 'interact':10 'irregular':36 'matter':12 'minor':39 'occasion':38 'provid':3 'python':31 'ray':9,19,43 'refer':4 'releas':33 'scatter':15,44 'section':23 'support':30 'synchrotron':48 'updat':40 'version':28 'x':8,18,42 'x-ray':7,17,41 'xraydb':1,2 'yield':25","created_at":"2026-06-07T13:01:51.342592+00:00","updated_at":"2026-06-07T13:01:51.342592+00:00","problems":[{"fix":"Delete the cache: rm -rf ~/.xraydb and re-run your script.","cause":"Outdated cached database after upgrading xraydb.","error":"DatabaseError: Database version mismatch. Expected 4.5.0, got 4.4.0"},{"fix":"Run your script again; the download will start automatically.  Alternatively, set XRAYDB_CACHE to a writable directory.","cause":"Database has not been downloaded or cache directory is missing.","error":"FileNotFoundError: [Errno 2] No such file or directory: '~/.xraydb/xraydb.sqlite'"},{"fix":"Use the XrayDB class: from xraydb import XrayDB; db = XrayDB(); results = db.mu(...)","cause":"Function removed in xraydb 4.0.0.","error":"ImportError: cannot import name 'get_xraydata' from 'xraydb'"},{"fix":"Use valid element symbols e.g., 'Fe', 'Cu'.  Case-sensitive.","cause":"Invalid element symbol passed to a function.","error":"ValueError: Element 'Uu' not found"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/xraypy/XrayDB","github":"https://github.com/xraypy/XrayDB","docs":null,"changelog":null,"pypi":null,"npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["science"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":null}}