Skip to main content

To Temp logo

ToTemp

package version license pre-commit.ci Documentation Status

ToTemp is a temperature conversion package with Celsius, Delisle, Fahrenheit, Kelvin, Rankine, Réaumur, Newton and Rømer scales.

For more information read the docs.

This package aims to bring the simple and straight to the point, but precise, Object Oriented experience of working with temperature scale data types.


Usage

First of all, install the package:

pip install totemp

or, to have an example in poetry environments:

poetry add totemp

For more information, read the docs: [ToTemp Docs]('insert link here')

The instances:

from totemp import Celsius, Fahrenheit

if __name__ == '__main__':
    temps: list = [Celsius(12), Celsius(25), Celsius(50)]
    print(temps[0])  # '12 ºC'
    print(temps)  # [Celsius(12), Celsius(25), Celsius(50)]

    temps = list(map(Celsius.to_fahrenheit, temps))
    print(temps[0])  # '53.6 ºF'
    print(temps)  # [Fahrenheit(53.6), Fahrenheit(77.0), Fahrenheit(122.0)]

It's representations and properties:

Property symbol is read-only.

from totemp import Fahrenheit

if __name__ == '__main__':
    temp0 = Fahrenheit(53.6)
    print(temp0.__repr__())  # 'Fahrenheit(53.6)'
    print(temp0.__str__())  # '53.6 ºF'
    print(temp0.symbol)  # 'ºF'
    print(temp0.value)  # 53.6

Comparision operations ('==', '!=', '>', '>=', '<',...):

The comparision/arithmetic implementation attempts to convert the value of other (if it is a temperature instance) and then evaluate the expression.

import totemp as tp

if __name__ == '__main__':
    temp0, temp1 = tp.Celsius(0), tp.Fahrenheit(32)

    print(f'temp0: {repr(temp0)}')  # Celsius(0)
    print(f'temp1: {repr(temp1.to_celsius())}')  # Celsius(0.0)

    print(temp0 != temp1)  # False

    print(temp0 > temp1)  # False

    print(temp0 < temp1)  # False

    print(temp0 >= temp1)  # True

    print(temp0 <= temp1)  # True

    print(temp0 == temp1)  # True

Arithmetic operations ('+', '-', '*', '**', '/', '//', '%', ...):

from totemp import Newton, Rankine

if __name__ == '__main__':
    temp0 = Newton(33)
    temp1 = Rankine(671.67)

    temp2 = temp0 + temp1

    print('temp2:', temp2)  # temp2: 65.99999999999999 ºN
    print('temp2:', repr(temp2))  # temp2: Newton(65.99999999999999)
    print('temp2:', temp2.value, temp2.symbol)  # temp2: 65.99999999999999 ºN

    print((temp0 + temp1).rounded())  # 66 ºN
    print(repr((temp0 + temp1).rounded()))  # Newton(66)

    print(temp2 + 12.55)  # 78.54999999999998 ºN
    print((12 + temp2.rounded()))  # 78 ºN

ToTemp classes can work with many built-in Python functions:

from math import floor, ceil, trunc

from totemp import Reaumur

if __name__ == '__main__':
    temp = Reaumur(100.4)

    float(temp)  # 100.4
    int(temp)  # 100
    round(temp)  # Reaumur(100)
    abs(temp)  # Reaumur(100)
    floor(temp)  # Reaumur(100)
    ceil(temp)  # Reaumur(101)
    trunc(temp)  # Reaumur(100)
    divmod(temp, temp0 := Reaumur(25.1))  # (Reaumur(4.0), Reaumur(0.0))

Temperature Instance Conversions:

import totemp

if __name__ == '__main__':
    temp = totemp.Fahrenheit(32)

    print(temp.to_celsius())  # 0.0 ºC
    print(temp.to_fahrenheit())  # 32 ºF
    print(temp.to_delisle())  # 150.0 ºDe
    print(temp.to_kelvin())  # 273.15 K
    print(temp.to_newton())  # 0.0 ºN
    print(temp.to_rankine())  # 491.67 ºR
    print(temp.to_reaumur())  # 0.0 ºRé
    print(temp.to_romer())  # 7.5 ºRø

Changelog


  • 0.1.0:

    • Yanked, not functional;
  • 0.2.0:

    • Functional;
    • Can convert Celsius to Delisle, Fahrenheit, Kelvin, Newton, Rankine, Réaumur and Rømer.
  • 0.3.0:

    • Changed methods implementations and adds Fahrenheit conversions;
      • <scale_value> parameter is now positional-only;
      • Adds new parameter -> float_ret -> Float Return (True by default, keyword-only);
      • Celsius class methods were updated and enhanced;
      • Can now convert Fahrenheit to Celsius, Delisle, Kelvin, Newton, Rankine, Réaumur and Rømer.
  • 0.4.0:

    • There are two new Classes, Kelvin and Delisle, functional and ready-to-use.
  • 0.5.1:

    • The implementation has been completely refactored:

      1 - All classes inhehits from AbstractTemperature (our new abstract Base Class);

      2 - All classes now available:

      • Celsius;
      • Fahrenheit;
      • Delisle;
      • Kelvin;
      • (*New) Newton;
      • (*New) Rankine;
      • (*New) Réaumur;
      • (*New) Rømer.

      3 - New features:

      • The majority of Python's built-in functions works with the instances;
      • More pythonic properties and methods implementations;
      • Arithmetic operations;
      • Comparision operations;
      • convert_to() method;

      4 - Removals:

      • precise() method;
      • float_ret() param;
      • differentiating int/float;

      5 - Known problemns:

      • pow() doesn't work as intended;

License

For more information, check LICENSE file.

Metadata

Release files for totemp 0.5.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 totemp 0.5.1
File Size Uploaded Provenance
totemp-0.5.1.tar.gz 22.6 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 42.7 kB

Release files / totemp-0.5.1.tar.gz

Download URL totemp-0.5.1.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
94af38a6efcec925af37b3d3c9c13bae7207f4c9520715d079b3a055efd2c64f
BLAKE2b-256 checksum
How to use checksums
f2285c9253caebbee515dc3ec0cc7392b354e9ee8b0fec59a244cee8922de310
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.1 Windows/10

Release files / totemp-0.5.1-py3-none-any.whl

Download URL totemp-0.5.1-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
809874867d555f5b8c65715405d4679e93563b4449a7599bf36fd08cd546a9ba
BLAKE2b-256 checksum
How to use checksums
39991a09c8f77ad2299951eefd10263f872035878fd894f91ddf9909d4b1812e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.1 Windows/10

Security for totemp 0.5.1

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.

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files No provenance

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