Skip to main content

physu

A modular Python physics library with strict unit and dimensional validation powered by Pint.

Features

  • Strict dimensional safety: Rejects incompatible dimensions (such as mass where velocity is expected) via pint.DimensionalityError.
  • Physical domain validation: Rejects non-physical inputs (negative time, zero radius, unreachable trajectories, NaN, or non-finite values) via PhysicalDomainError (a ValueError subclass).
  • Centralized UnitRegistry: Shares a single physu.ureg across all modules and normalizes strings ("72 km/h"), physu.ureg quantities, and quantities from external Pint registries.
  • Clean SI outputs: Calculations return normalized SI pint.Quantity objects that can be converted to any compatible unit with .to(...).

Installation

pip install physu

For local development (including pytest, ruff, and mypy):

pip install -e ".[dev]"

Requires Python >= 3.10.

Quickstart

import pint
from physu import PhysicalDomainError, ureg
from physu.constants import STANDARD_GRAVITY
from physu.kinematics import (
    accelerated_displacement,
    centripetal_acceleration,
    displacement,
    projectile_range,
    time_to_height,
)

# 1D Uniform Motion (MRU)
dx = displacement("72 km/h", "10 s")
print(dx)            # 200.0 meter
print(dx.to("km"))   # 0.2 kilometer

# 1D Uniformly Accelerated Motion (MRUA)
dx_acc = accelerated_displacement(10 * (ureg.m / ureg.s), "2 m/s^2", "5 s")
print(dx_acc)        # 75.0 meter

# Vertical Motion (returns both times when reaching 15 m: going up & coming down)
times = time_to_height("20 m/s", "15 m", gravity="10 m/s^2")
print(times)         # (Quantity(1.0, "second"), Quantity(3.0, "second"))

# 2D Projectile Motion
rng = projectile_range("20 m/s", "45 deg", gravity=STANDARD_GRAVITY)
print(round(rng, 2)) # 40.79 meter

# Uniform Circular Motion (UCM)
ac = centripetal_acceleration("2 m", angular_velocity="60 rpm")
print(round(ac, 2))  # 78.96 meter / second ** 2

# Catching dimensional & physical errors
try:
    displacement("10 kg", "2 s")
except pint.DimensionalityError as exc:
    print("Dimension error:", exc)

try:
    time_to_height("20 m/s", "25 m", gravity="10 m/s^2")
except PhysicalDomainError as exc:
    print("Domain error:", exc)

Modules

  • physu.units: Centralized ureg, Quantity, to_quantity, check_dimension, convert_to, to_si, and to_unit.
  • physu.exceptions: PhysuError and PhysicalDomainError.
  • physu.validation: validate_quantity, require_non_negative, require_positive, require_non_zero, and require_range.
  • physu.constants: Fundamental SI / CODATA 2022 constants (STANDARD_GRAVITY, SPEED_OF_LIGHT, GRAVITATIONAL_CONSTANT, PLANCK_CONSTANT, ELEMENTARY_CHARGE, BOLTZMANN_CONSTANT, AVOGADRO_CONSTANT, MOLAR_GAS_CONSTANT, STANDARD_ATMOSPHERE, ELECTRON_MASS, PROTON_MASS, VACUUM_PERMITTIVITY, VACUUM_PERMEABILITY).
  • physu.kinematics:
    • uniform: MRU (displacement, position, average_velocity, travel_time)
    • accelerated: MRUA / SUVAT (final_velocity, displacement, position, displacement_from_velocities, acceleration, torricelli_velocity, time_to_velocity, time_to_displacement)
    • vertical: Free fall and vertical throw (vertical_position, vertical_velocity, free_fall_distance, free_fall_speed, free_fall_time, time_to_peak, max_height, time_to_height)
    • projectile: 2D projectile motion (velocity_components, projectile_flight_time, projectile_max_height, projectile_range, projectile_position, projectile_velocity)
    • circular: Uniform circular motion (tangential_speed, angular_velocity_from_speed, centripetal_acceleration, period_from_frequency, frequency_from_period, angular_velocity_from_period, angular_velocity_from_frequency, period_from_angular_velocity, frequency_from_angular_velocity, angular_displacement, arc_length)

Development

pytest
ruff check src tests
mypy src

License

MIT

Metadata

Release files for physu 0.1.0

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

Source distribution (sdist)

Source distribution for physu 0.1.0
File Size Uploaded Provenance Actions
physu-0.1.0.tar.gz 16.3 kB Without provenance Details for physu-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 34.1 kB

Release files / physu-0.1.0.tar.gz

Download URL physu-0.1.0.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
181a3f8840efc1a1b5949f7807f264d209be19d670fc9ae9e3db6fd4f87922a5
BLAKE2b-256 checksum
How to use checksums
5ecc67def7bdeb96d52ab7845671d09d09e8353c1bf5d7c281dfdb2a84a2ad93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / physu-0.1.0-py3-none-any.whl

Download URL physu-0.1.0-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd93b4d4e23c0209c06ade0cdc4ed511dad37c136e571c85cfb22a7c4c0eec14
BLAKE2b-256 checksum
How to use checksums
3a2160133b2391b39ae900e11770684ea597df9f2ad1b853b86b2f27c1c1a083
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for physu 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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