This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<spanid="unit-converter"></span><spanid="unit-converter-plugin"></span><h1>Unit Converter<aclass="headerlink"href="#module-searx.plugins.unit_converter"title="Link to this heading">¶</a></h1>
<p>A plugin for converting measured values from one unit to another unit (a
unit converter).</p>
<p>The plugin looks up the symbols (given in the query term) in a list of
converters, each converter is one item in the list (compare
<aclass="reference internal"href="#searx.plugins.unit_converter.ADDITIONAL_UNITS"title="searx.plugins.unit_converter.ADDITIONAL_UNITS"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">ADDITIONAL_UNITS</span></code></a>). If the symbols are ambiguous, the matching units
of measurement are evaluated. The weighting in the evaluation results from the
sorting of the <aclass="reference internal"href="#searx.plugins.unit_converter.symbol_to_si"title="searx.plugins.unit_converter.symbol_to_si"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">list</span><spanclass="pre">of</span><spanclass="pre">unit</span><spanclass="pre">converters</span></code></a>.</p>
<p>Enable in <codeclass="docutils literal notranslate"><spanclass="pre">settings.yml</span></code>:</p>
<spanclass="sig-prename descclassname"><spanclass="pre">searx.plugins.unit_converter.</span></span><spanclass="sig-name descname"><spanclass="pre">ADDITIONAL_UNITS</span></span><emclass="property"><spanclass="w"></span><spanclass="p"><spanclass="pre">=</span></span><spanclass="w"></span><spanclass="pre">[{'from_si':</span><spanclass="pre"><function</span><spanclass="pre"><lambda>>,</span><spanclass="pre">'si_name':</span><spanclass="pre">'Q11579',</span><spanclass="pre">'symbol':</span><spanclass="pre">'°C',</span><spanclass="pre">'to_si':</span><spanclass="pre"><function</span><spanclass="pre"><lambda>>},</span><spanclass="pre">{'from_si':</span><spanclass="pre"><function</span><spanclass="pre"><lambda>>,</span><spanclass="pre">'si_name':</span><spanclass="pre">'Q11579',</span><spanclass="pre">'symbol':</span><spanclass="pre">'°F',</span><spanclass="pre">'to_si':</span><spanclass="pre"><function</span><spanclass="pre"><lambda>>}]</span></em><aclass="headerlink"href="#searx.plugins.unit_converter.ADDITIONAL_UNITS"title="Link to this definition">¶</a></dt>
<dd><p>Additional items to convert from a measure unit to a SI unit (vice versa).</p>
<spanclass="s2">"si_name"</span><spanclass="p">:</span><spanclass="s2">"Q11579"</span><spanclass="p">,</span><spanclass="c1"># Wikidata item ID of the SI unit (Kelvin)</span>
<spanclass="s2">"symbol"</span><spanclass="p">:</span><spanclass="s2">"°C"</span><spanclass="p">,</span><spanclass="c1"># symbol of the measure unit</span>
<spanclass="s2">"to_si"</span><spanclass="p">:</span><spanclass="k">lambda</span><spanclass="n">val</span><spanclass="p">:</span><spanclass="n">val</span><spanclass="o">+</span><spanclass="mf">273.15</span><spanclass="p">,</span><spanclass="c1"># convert measure value (val) to SI unit</span>
<spanclass="s2">"from_si"</span><spanclass="p">:</span><spanclass="k">lambda</span><spanclass="n">val</span><spanclass="p">:</span><spanclass="n">val</span><spanclass="o">-</span><spanclass="mf">273.15</span><spanclass="p">,</span><spanclass="c1"># convert SI value (val) measure unit</span>
<spanclass="s2">"to_si"</span><spanclass="p">:</span><spanclass="mf">1609.344</span><spanclass="p">,</span><spanclass="c1"># convert measure value (val) to SI unit</span>
<spanclass="s2">"from_si"</span><spanclass="p">:</span><spanclass="mi">1</span><spanclass="o">/</span><spanclass="mf">1609.344</span><spanclass="c1"># convert SI value (val) measure unit</span>
<spanclass="p">},</span>
</pre></div>
</div>
<p>The values of <codeclass="docutils literal notranslate"><spanclass="pre">to_si</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">from_si</span></code> can be of <aclass="reference external"href="https://docs.python.org/3/library/functions.html#float"title="(in Python v3.13)"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">float</span></code></a> (a multiplier)
or a <aclass="reference external"href="https://docs.python.org/3/glossary.html#term-callable">callable</a> (val in / converted value returned).</p>
<spanclass="sig-prename descclassname"><spanclass="pre">searx.plugins.unit_converter.</span></span><spanclass="sig-name descname"><spanclass="pre">ALIAS_SYMBOLS</span></span><emclass="property"><spanclass="w"></span><spanclass="p"><spanclass="pre">=</span></span><spanclass="w"></span><spanclass="pre">{'mi':</span><spanclass="pre">('L',),</span><spanclass="pre">'°C':</span><spanclass="pre">('C',),</span><spanclass="pre">'°F':</span><spanclass="pre">('F',)}</span></em><aclass="headerlink"href="#searx.plugins.unit_converter.ALIAS_SYMBOLS"title="Link to this definition">¶</a></dt>
<dd><p>Alias symbols for known unit of measure symbols / by example:</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="s1">'°C'</span><spanclass="p">:</span><spanclass="p">(</span><spanclass="s1">'C'</span><spanclass="p">,</span><spanclass="o">...</span><spanclass="p">),</span><spanclass="c1"># list of alias symbols for °C (Q69362731)</span>
<spanclass="s1">'°F'</span><spanclass="p">:</span><spanclass="p">(</span><spanclass="s1">'F'</span><spanclass="p">,</span><spanclass="o">...</span><spanclass="p">),</span><spanclass="c1"># list of alias symbols for °F (Q99490479)</span>
<spanclass="s1">'mi'</span><spanclass="p">:</span><spanclass="p">(</span><spanclass="s1">'L'</span><spanclass="p">,),</span><spanclass="c1"># list of alias symbols for mi (Q253276)</span>
<spanclass="sig-prename descclassname"><spanclass="pre">searx.plugins.unit_converter.</span></span><spanclass="sig-name descname"><spanclass="pre">symbol_to_si</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../../_modules/searx/plugins/unit_converter.html#symbol_to_si"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#searx.plugins.unit_converter.symbol_to_si"title="Link to this definition">¶</a></dt>
<dd><p>Generates a list of tuples, each tuple is a measure unit and the fields
in the tuple are:</p>
<olclass="arabic simple"start="0">
<li><p>Symbol of the measure unit (e.g. ‘mi’ for measure unit ‘miles’ Q253276)</p></li>
<li><p>SI name of the measure unit (e.g. Q11573 for SI unit ‘metre’)</p></li>
<li><p>Factor to get SI value from measure unit (e.g. 1mi is equal to SI 1m
multiplied by 1609.344)</p></li>
<li><p>Factor to get measure value from from SI value (e.g. SI 100m is equal to
100mi divided by 1609.344)</p></li>
</ol>
<p>The returned list is sorted, the first items are created from
<codeclass="docutils literal notranslate"><spanclass="pre">WIKIDATA_UNITS</span></code>, the second group of items is build from
<aclass="reference internal"href="#searx.plugins.unit_converter.ADDITIONAL_UNITS"title="searx.plugins.unit_converter.ADDITIONAL_UNITS"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">ADDITIONAL_UNITS</span></code></a> and items created from <aclass="reference internal"href="#searx.plugins.unit_converter.ALIAS_SYMBOLS"title="searx.plugins.unit_converter.ALIAS_SYMBOLS"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">ALIAS_SYMBOLS</span></code></a>.</p>
<p>If you search this list for a symbol, then a match with a symbol from
Wikidata has the highest weighting (first hit in the list), followed by the
symbols from the <aclass="reference internal"href="#searx.plugins.unit_converter.ADDITIONAL_UNITS"title="searx.plugins.unit_converter.ADDITIONAL_UNITS"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">ADDITIONAL_UNITS</span></code></a> and the lowest weighting is
given to the symbols resulting from the aliases <aclass="reference internal"href="#searx.plugins.unit_converter.ALIAS_SYMBOLS"title="searx.plugins.unit_converter.ALIAS_SYMBOLS"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">ALIAS_SYMBOLS</span></code></a>.</p>