Skip to main content

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

sciform

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

Overview

sciform is used to convert python numbers into strings according to a variety of user-selected scientific formatting options including fixed-point, scientific and engineering formats. Where possible, formatting follows documented standards such as those published by BIPM. 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).

Installation

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+https://github.com/jagerber48/sciform.git

sciform is compatible with Python versions >=3.8.

Usage

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))
123.5e+03

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}")
12000
>>> print(f"{num:!2r}")
12e+03

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()}")
123456.6543(34)

Note that the above examples demonstrate that sciform uses “round-to-even” rounding:

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

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] flag.

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.

Acknowledgements

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

Metadata

Release files for sciform 0.39.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sciform 0.39.1
File Size Uploaded
sciform-0.39.1.tar.gz 213.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sciform 0.39.1
File Interpreter ABI Platform
sciform-0.39.1-py3-none-any.whl Python 3 none any Details

Total release size: 253.7 kB

Release files / sciform-0.39.1.tar.gz

Download URL sciform-0.39.1.tar.gz
Size 213.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7d7eb43a2efa2d60732141fbaa2108b3f34e2f85ce79d3ac22d8ddb9e19731c6
BLAKE2b-256 checksum
How to use checksums
01f7351f7d9700e77b094e15a923648edee71dd969c58857610ddc33f9b6ddc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

Release files / sciform-0.39.1-py3-none-any.whl

Download URL sciform-0.39.1-py3-none-any.whl
Size 40.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
86d7e9dde3182f6b1f3318526f3ba42a2f3d0a3f275e9388beca32f185e76fb3
BLAKE2b-256 checksum
How to use checksums
9103445ccadec66c040a283a9e2b57e9098029767fe45422f8c6c346834f6501
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

Release history Release notifications | RSS feed

This release

0.39.1 This release

2 release files

0.39.0

2 release files

0.35.0

2 release files

0.34.1

2 release files

0.33.0

2 release files

0.32.3

2 release files

0.32.2

2 release files

0.32.0

2 release files

0.30.1

2 release files

0.30.0

2 release files

0.29.1

2 release files

0.28.2

2 release files

0.28.1

2 release files

0.28.0

2 release files

0.27.4

2 release files

0.27.3

2 release files

0.27.2

2 release files

0.27.1

2 release files

0.27.0

2 release files

0.26.2

2 release files

0.26.1

2 release files

0.26.0

2 release files

0.25.2

2 release files

0.25.1

2 release files

0.24.0

2 release files

0.23.0

2 release files

0.22.2

2 release files

0.22.1

2 release files

0.20.1

2 release files

0.20.0

2 release files

0.19.0

2 release files

0.18.1

2 release files

0.18.0

2 release files

0.17.1

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.2

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.2

2 release files

0.13.1

2 release files

0.13.0

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page