Skip to main content

FaSt_PUC converts numbers to strings with appropriate unit prefix.

Project description

FaSt_PUC

FaSt_PUC is a Python package that provides pretty unit conversion with automatic SI prefix selection. It intelligently formats numbers with appropriate metric prefixes (like k, M, G, µ, n, etc.) to make them more readable.

Features

  • Automatic selection of SI prefixes from atto (a) to peta (P)
  • Support for custom unit strings
  • Special formatting options for percentages and decibels
  • File name compatible output
  • Configurable precision
  • Support for NumPy arrays
  • No external dependencies except NumPy

Installation

Install using pip:

pip install fast-puc

Basic Usage

Import the package and call the main function:

from fast_puc import puc

# Basic number formatting
puc(1.0001)         # "1"
puc(1.0001, "m")    # "1m"
puc(0.991e-6, "s")  # "991ns"
puc(1030e-9, "m")   # "1.03µm"
puc(999.999, "W")   # "1kW"

Advanced Features

Custom Separators and Special Formats

# Custom separators
puc(1.0001, " m")   # "1 m"    # with space separator
puc(1.0001, "_m")   # "1_m"    # with underscore separator

# Special formats
puc(0.911, "%")     # "91.1%"  # convert to percent
puc(1001, "dB")     # "30dB"   # convert to dB
puc(1030e-9, "!m")  # "1p03um" # file name compatible with special character !

Precision Control

puc(1.2345, "m", precision=2)      # "1.2m"
puc(0.012345, "m", precision=2)    # "12mm"
puc(0.000123456, "m", precision=5) # "123460nm"

Advanced Options

The puc function accepts several optional parameters:

puc(value,               # Number to format (float or numpy array)
    unit="",            # Unit string with optional modifiers
    precision=3,        # Number of significant digits
    verbose=False,      # Return additional formatting info
    filecompatible=False) # Make output safe for filenames

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

Licensed under MIT License. See LICENSE for details.

Author

Written by Fabian Stutzki (fast@fast-apps.de)

For more information, visit https://www.fast-apps.de

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast_puc-0.2.1.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fast_puc-0.2.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file fast_puc-0.2.1.tar.gz.

File metadata

  • Download URL: fast_puc-0.2.1.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.30

File hashes

Hashes for fast_puc-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fe09a3eb2767cdb7e4aec745e3f3450bc13257eee08590d4a33685e97dce3232
MD5 1c08f3a4a8668e1ba02bc5de6a3899fc
BLAKE2b-256 9fafc889c1a5bbd03002f8e628e81df508336de6f822252b7b7c6d37e10174e6

See more details on using hashes here.

File details

Details for the file fast_puc-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: fast_puc-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.30

File hashes

Hashes for fast_puc-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d4989501a357890020b47f2d120f561dce3c71d0b6d7706072701dea09da55a6
MD5 343f23cf6af751dfe103e7329012fb73
BLAKE2b-256 09e40b7f8d145437ff28d233e91007e8bc0ab2216b8ee16e922178f5b4945694

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page