A powerful and easy-to-use Python library for unit conversion and calculations.
Project description
Unifyt v0.2.0
A powerful and easy-to-use Python library for unit conversion and calculations, combining the best features of Pint and Unyt.
🌟 Why Unifyt?
Unifyt solves the universal problem of working with physical units in scientific computing, engineering, and data analysis. It prevents errors, saves time, and makes your code clear and maintainable.
Before Unifyt:
distance = 100 # meters? kilometers? 🤔
speed = distance / 10 # What unit is this? 😕
With Unifyt:
from unifyt import Quantity
distance = Quantity(100, 'meter')
speed = distance / Quantity(10, 'second') # Automatically: 10 m/s ✨
print(speed.to('kilometer/hour')) # 36.0 km/h 🎯
Features
- Intuitive API: Simple and Pythonic interface for working with physical quantities
- Extensive Unit Support: 300+ units including SI, imperial, astronomical, atomic, electromagnetic, and more
- Wire Gauge Support: AWG, SWG, BWG conversions for electrical and mechanical applications
- Torque Units: Convenient shortcuts for newton-meter, foot-pound, inch-pound
- Industrial Units: GSM, mass flow rates, volumetric flow rates, angular velocity
- High Performance: Optimized for speed with caching and NumPy integration
- Type Safety: Full type hints for better IDE support
- Flexible Conversions: Easy unit conversions with automatic dimensionality checking
- Array Support: Seamless integration with NumPy arrays
- Custom Units: Define your own units and unit systems
- Context Management: Switch between unit systems easily
- Physical Constants: Built-in library of 80+ physical and astronomical constants
- Utility Functions: Array creation, statistical operations, and more
- Serialization: Save and load quantities in JSON or pickle format
🎉 What's New in v0.2.0
- 300+ units (3x increase from v0.1.0!)
- 80+ constants (2.7x increase!)
- 25+ exception types for precise error handling
- 15+ new categories: Electromagnetic, radioactivity, data storage, viscosity, and more
- Wire gauge support: AWG, SWG, BWG conversions
- Torque units: Newton-meter, foot-pound, inch-pound shortcuts
- Industrial units: GSM, mass flow rates, volumetric flow rates, angular velocity
- Comprehensive documentation: 10+ new guides including WHY_UNIFYT.md, EXCEPTIONS_GUIDE.md
- Fully backward compatible - All existing code works
- See CHANGELOG.md for complete details
- Custom Units: Define your own units and unit systems
- Context Management: Switch between unit systems easily
- Physical Constants: Built-in library of physical and astronomical constants
- Utility Functions: Array creation, statistical operations, and more
- Serialization: Save and load quantities in JSON or pickle format
Installation
pip install unifyt
🚀 Quick Start
New to Unifyt? Choose your path:
- 60 seconds: [START_HERE.md](starter documents/START_HERE.md) - Lightning fast intro
- 5 minutes: QUICKSTART.md - Quick tutorial
- Complete: COMPLETE_GUIDE.md - Everything you need
- Why use it: WHY_UNIFYT.md - Value proposition
pip install unifyt
from unifyt import Quantity, constants, utils, wire_gauge
import numpy as np
# Create quantities with units
distance = Quantity(100, 'meters')
time = Quantity(9.58, 'seconds')
# Perform calculations
speed = distance / time
print(speed) # 10.438413361169102 meter / second
# Convert units
speed_mph = speed.to('miles/hour')
print(speed_mph) # 23.350065963060686 mile / hour
# Work with arrays
distances = Quantity(np.array([100, 200, 300]), 'meters')
print(distances.to('kilometers')) # [0.1 0.2 0.3] kilometer
# Use physical constants
mass = Quantity(1, 'kilogram')
energy = mass * constants.c ** 2 # E = mc²
print(energy.to('kilowatt_hour'))
# Wire gauge conversions
wire_diameter = wire_gauge.awg_to_diameter(14) # AWG 14 wire
print(wire_diameter) # 1.628 millimeter
print(wire_diameter.to('inch')) # 0.0641 inch
# Torque calculations
torque = Quantity(100, 'newton_meter') # or 'Nm'
print(torque.to('foot_pound')) # 73.76 ft-lb
# Utility functions
temps = utils.linspace(Quantity(0, 'celsius'), Quantity(100, 'celsius'), 11)
mean_temp = utils.mean(temps)
Want more? → COMPLETE_GUIDE.md - The ultimate guide!
Need help? → QUICK_REFERENCE.md - Quick lookup!
📚 Documentation
🌟 Essential Guides (Start Here!)
- WHY_UNIFYT.md ⭐ - Why you need this library
- COMPLETE_GUIDE.md ⭐ - The ultimate guide
- QUICK_REFERENCE.md ⭐ - Quick lookup
- EXCEPTIONS_GUIDE.md ⭐ - Error handling
📚 Getting Started
- [START_HERE.md](starter documents/START_HERE.md) - 60-second intro
- QUICKSTART.md - 5-minute tutorial
- GETTING_STARTED.md - Comprehensive tutorial
- INDEX.md - Complete navigation hub
📖 Reference Documentation
- [UNITS_CATALOG.md](starter documents/UNITS_CATALOG.md) - All 300+ units
- docs/api_reference.md - Full API reference
- docs/user_guide.md - Complete usage guide
- docs/FEATURES.md - Detailed feature list
- examples/ - Practical examples
🔧 Advanced Topics
- docs/PERFORMANCE.md - Optimization guide
- docs/MIGRATION.md - Migrating from Pint/Unyt
📋 Project Information
- [FINAL_SUMMARY.md](starter documents/FINAL_SUMMARY.md) - Project summary
- STRUCTURE.md - Project structure
- CHANGELOG.md - Version history
- CONTRIBUTING.md - How to contribute
Examples
Check out the examples/ directory for more usage examples:
- basic_usage.py - Basic unit conversions and operations
- scientific_calculations.py - Physics, chemistry, and engineering examples
- custom_units.py - Define your own units
- array_operations.py - NumPy array integration
- advanced_features.py - Constants, utilities, and serialization
Development
Setup
# Clone the repository
git clone https://github.com/MEERAN2314/unifyt.git
cd unifyt
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -e ".[dev]"
Running Tests
pytest tests/
Code Quality
# Run linting
flake8 unifyt/
# Run type checking
mypy unifyt/
# Format code
black unifyt/ tests/
Contributing
Contributions are welcome! Please read our Contributing Guide for details.
License
MIT License - see LICENSE file for details.
Supported Units (300+)
Core Units
- Length: meter, kilometer, mile, foot, inch, nanometer, angstrom, parsec, light_year, etc.
- Mass: kilogram, gram, pound, ounce, ton, atomic_mass_unit, solar_mass, earth_mass, etc.
- Time: second, minute, hour, day, week, year, femtosecond, attosecond, millennium, etc.
- Temperature: kelvin, celsius, fahrenheit
Derived Units
- Energy: joule, calorie, kilowatt_hour, electronvolt, BTU, erg, rydberg, hartree, etc.
- Power: watt, kilowatt, horsepower, gigawatt, terawatt, etc.
- Pressure: pascal, bar, atmosphere, psi, torr, gigapascal, etc.
- Force: newton, dyne, kilogram_force, pound_force, kip, etc.
- Torque: newton_meter (Nm), foot_pound (ft-lb), inch_pound (in-lb), etc.
- Frequency: hertz, kilohertz, megahertz, gigahertz, terahertz, rpm, etc.
- Voltage: volt, millivolt, kilovolt, megavolt, etc.
- Current: ampere, milliampere, microampere, kiloampere, etc.
- Capacitance: farad, microfarad, nanofarad, picofarad, etc.
- Inductance: henry, millihenry, microhenry, etc.
- Magnetic Field: tesla, gauss, millitesla, etc.
- Radioactivity: becquerel, curie, rutherford, etc.
- Radiation Dose: gray, sievert, rad, rem, etc.
- Data: bit, byte, kilobyte, megabyte, gigabyte, terabyte, etc.
- Volume: liter, gallon, milliliter, cup, etc.
- Angle: radian, degree, arcminute, arcsecond, etc.
- Viscosity: poise, stokes, pascal_second, etc.
- Concentration: molar, millimolar, micromolar, etc.
- Flow Rates: liter_per_minute, cubic_foot_per_minute (cfm), kilogram_per_hour, ton_per_hour, etc.
- Angular Velocity: rpm, radian_per_second, degree_per_second, revolution_per_minute, etc.
- Paper/Fabric Weight: gsm (grams per square meter)
- And many more!
Wire Gauges
- AWG (American Wire Gauge): 0000, 000, 00, 0-44
- SWG (Standard Wire Gauge): 0-50
- BWG (Birmingham Wire Gauge): 0-36
from unifyt import wire_gauge
# Convert gauge to diameter
diameter = wire_gauge.awg_to_diameter(14) # 1.628 mm
diameter_in = wire_gauge.awg_to_diameter(14, 'inch') # 0.0641 in
# Find gauge from diameter
gauge = wire_gauge.diameter_to_awg(Quantity(1.6, 'mm')) # 14
Physical Constants (80+)
Access fundamental constants with proper units:
from unifyt import constants
# Fundamental
print(constants.c) # Speed of light
print(constants.h) # Planck constant
print(constants.G) # Gravitational constant
print(constants.N_A) # Avogadro number
print(constants.g) # Standard gravity
# Astronomical
print(constants.AU) # Astronomical unit
print(constants.M_sun) # Solar mass
print(constants.L_sun) # Solar luminosity
print(constants.H_0) # Hubble constant
# Atomic & Particle
print(constants.m_e) # Electron mass
print(constants.m_p) # Proton mass
print(constants.mu_B) # Bohr magneton
print(constants.lambda_C) # Compton wavelength
# Planck Units
print(constants.l_P) # Planck length
print(constants.t_P) # Planck time
print(constants.E_P) # Planck energy
# Electromagnetic
print(constants.Z_0) # Vacuum impedance
print(constants.Phi_0) # Magnetic flux quantum
# Cosmological
print(constants.T_CMB) # CMB temperature
print(constants.universe_age) # Age of universe
🎯 Real-World Applications
- Physics: Kinetic energy, gravitational force, E=mc²
- Engineering: Flow rates, power calculations, pressure conversions
- Chemistry: Concentration calculations, ideal gas law
- Data Analysis: Sensor data, environmental monitoring
- Astronomy: Light-year distances, escape velocity
- Education: Teaching physics, chemistry labs
See COMPLETE_GUIDE.md for detailed examples!
Acknowledgments
This library is inspired by and builds upon the excellent work of:
Changelog
See CHANGELOG.md for version history.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unifyt-0.2.2.tar.gz.
File metadata
- Download URL: unifyt-0.2.2.tar.gz
- Upload date:
- Size: 67.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ceb4efdaf4e544c97a46337e87e4fc8db9d6a3e2a8a550a7a6e376b075a2225
|
|
| MD5 |
fa60c4a22f90e327e6bba36c40706fe6
|
|
| BLAKE2b-256 |
f34cbbcf3fb4a00819e88a032b2e10fcddffe36cb4192fd02f7cb5546fcd0d2a
|
Provenance
The following attestation bundles were made for unifyt-0.2.2.tar.gz:
Publisher:
publish.yml on MOHAMEDHADHI/Unifyt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unifyt-0.2.2.tar.gz -
Subject digest:
0ceb4efdaf4e544c97a46337e87e4fc8db9d6a3e2a8a550a7a6e376b075a2225 - Sigstore transparency entry: 984764401
- Sigstore integration time:
-
Permalink:
MOHAMEDHADHI/Unifyt@c4cd0c558851079dea20a1ef66e961add79f9ae1 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/MOHAMEDHADHI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c4cd0c558851079dea20a1ef66e961add79f9ae1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file unifyt-0.2.2-py3-none-any.whl.
File metadata
- Download URL: unifyt-0.2.2-py3-none-any.whl
- Upload date:
- Size: 38.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a814e2f4d3e765f11154a4cd8c432c0f67a301e9e7596567d604bf9ac90eea73
|
|
| MD5 |
f30fd9b29838b084e11ecb3ffcb91782
|
|
| BLAKE2b-256 |
ad85372abedd9d0b79bd02041a3b560fb46f4e09e69ff02563f61f9686d49e64
|
Provenance
The following attestation bundles were made for unifyt-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on MOHAMEDHADHI/Unifyt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unifyt-0.2.2-py3-none-any.whl -
Subject digest:
a814e2f4d3e765f11154a4cd8c432c0f67a301e9e7596567d604bf9ac90eea73 - Sigstore transparency entry: 984764409
- Sigstore integration time:
-
Permalink:
MOHAMEDHADHI/Unifyt@c4cd0c558851079dea20a1ef66e961add79f9ae1 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/MOHAMEDHADHI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c4cd0c558851079dea20a1ef66e961add79f9ae1 -
Trigger Event:
release
-
Statement type: