Sign inDemoInstall


Package Overview
File Explorer

Install Socket

Protect your apps from supply chain attacks



A package for formatting numbers into scientific formatted strings.




.. image::
     :alt: Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.
.. image::
     :alt: pyOpenSci
.. image::
     :alt: Read the Docs
.. image::
     :alt: PyPI - Version
.. image::
     :alt: PyPI - Python Version
.. image::
     :alt: Codecov
.. image::
     :alt: GitHub Workflow Status
.. image::
     :alt: Zenodo


|  **Repository:** `<>`_
|  **Documentation:** `<>`_
|  **PyPi:** `<>`_

We would greatly appreciate you taking the time to fill out the
`User Experience Survey <>`_ to help
improve ``sciform``.


``sciform`` is used to convert python numbers into strings according to
a variety of user-selected scientific formatting options including
decimal, binary, fixed-point, scientific and engineering formats.
Where possible, formatting follows documented standards such as those
published by `BIPM <>`_ or
`IEC <>`_.
``sciform`` provides certain options, such as engineering notation,
well-controlled significant figure rounding, and separator customization
which are not provided by the python built-in
`format specification mini-language (FSML) <>`_.


Install the latest stable version from
`PyPi <>`_ with::

   python -m pip install sciform

or install the latest development version from
`GitHub <>`_ with::

   python -m pip install git+

``sciform`` is compatible with Python versions >=3.9.


Here we provide a few key usage examples.
For many more details see
`Usage <>`_.

``sciform`` provides a wide variety of formatting options which can be
controlled when constructing ``Formatter`` objects which are then used
to format numbers into strings according to the selected options.

>>> from sciform import Formatter
>>> formatter = Formatter(
...     round_mode="dec_place", ndigits=6, upper_separator=" ", lower_separator=" "
... )
>>> print(formatter(51413.14159265359))
51 413.141 593
>>> formatter = Formatter(round_mode="sig_fig", ndigits=4, exp_mode="engineering")
>>> print(formatter(123456.78))

Users can also format numbers by constructing ``SciNum`` objects and
using string formatting to format the ``SciNum`` instances according
to a custom FSML.

>>> from sciform import SciNum
>>> num = SciNum(12345)
>>> print(f"{num:!2f}")
>>> print(f"{num:!2r}")

In addition to formatting individual numbers, ``sciform`` can be used
to format pairs of numbers as value/uncertainty pairs.
This can be done by passing two numbers into a ``Formatter`` call or by
using the ``SciNum`` object.

>>> formatter = Formatter(ndigits=2, upper_separator=" ", lower_separator=" ")
>>> print(formatter(123456.654321, 0.00345))
123 456.654 3 ± 0.003 4
>>> formatter = Formatter(ndigits=4, exp_mode="engineering")
>>> print(formatter(123456.654321, 0.00345))
(123.456654321 ± 0.000003450)e+03

>>> num = SciNum(123456.654321, 0.00345)
>>> print(f"{num:!2f}")
123456.6543 ± 0.0034
>>> print(f"{num:!2f()}")

Note that the above examples demonstrate that ``sciform`` uses
`"round-to-even" <>`_

>>> print(f"{SciNum(865):!2}")
>>> print(f"{SciNum(875):!2}")

See `Formatting Options <>`_,
`Format Specification Mini-Language <>`_
for more details and
`Examples <>`_ for
more examples.

Project Status

``sciform`` adheres to `semantic versioning <>`_.
The major version for ``sciform`` is still ``0`` indicating that
``sciform`` is still in the development stage which means there may be
backwards-incompatible changes to the interface (e.g. function or object
behaviors and names) without a corresponding major version bump.
All changes are announced after new releases in the
`changelog <>`_.
Backwards incompatible changes are indicated with the **[BREAKING]**

We are very excited to get your feedback to help stabilize the interface
and make ``sciform`` a more useful tool.
You can provide your feedback on your experience with ``sciform`` by
filling out
`the user experience survey <>`_.
Now is a great time to share your ``sciform`` ideas or issues by
opening a
`discussion <>`_ or
`issue <>`_.
If you would like to contribute to ``sciform`` then please see
`How to Contribute <>`_.

``sciform`` has undergone
`peer review <>`_
by the `PyOpenSci <>`_ community and been
accepted into the PyOpenSci ecosystem.
You can view the review
`here <>`_.


``sciform`` was heavily motivated by the prefix formatting provided in
the `prefixed <>`_
package and the value ± uncertainty formatting in the
`uncertainties <>`_ package.


Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.


Related posts

SocketSocket SOC 2 Logo


  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc