Skip to main content

Python package for converting various units.

Project description

Python minimum version Test-pytest Format-Ruff Lint-Ruff

unic

unic is a python package that can convert various units.

Conversion Targets

  • The current available conversion targets are as follows.

    Time Unit
    • TimeModel
      • minute / second / milisecond → hour
      • hour / second / milisecond → minute
      • hour / minute / milisecond → second
      • hour / minute / second → milisecond
    • DatetimeModel
      • unixtime / unixtime+timezone → datetime.datetime
      • unixtime / unixtime+timezone → datetime.date
    • UnixtimeModel
      • string(yyyy-mm-dd hh:mm:ss) / string(yyyy-mm-dd hh:mm:ss)+timezone → unixtime(default is seconds)
      • string(yyyy/mm/dd hh:mm:ss) / string(yyyy/mm/dd hh:mm:ss)+timezone → unixtime(default is seconds)
    Length Unit
    • MetricSystemModel
      • Target Metric System Units

        nm, um, mm, cm, m, km, Mm, Gm, Tm
        

        ※ um : represents ㎛.

      • The target metric system units are can be converted to each other.

Installing

pip install unic

How to

Example

Time Unit

TimeModel

import unic


convert_model = unic.load_model("time")

# Convert hour to minute (single value)
convert_min = convert_model.convert(2, from_unit="hour", to_unit="min")

# Convert hour to minute (list)
convert_min = convert_model.convert([2, 4, 6], from_unit="hour", to_unit="min")

# Convert hour to minute (batch processing) -- deprecated
convert_min = convert_model.convert_batch([2,4,6], from_unit="hour", to_unit="min")

DatetimeModel

import unic


convert_model = unic.load_model("datetime")

# Convert to datatime (single value)
convert_datetime = convert_model.convert(1577841753, format="datetime")

#Convert to datatime (list)
convert_min = convert_model.conver([1577841753,1577941753], format="datetime")

# Convert to datatime (batch processing) -- deprecated
convert_datetime = convert_model.convert_batch([1577841753,1577941753], format="datetime")

# Convert to date
convert_datetime = convert_model.convert(1577841753, format="date")

UnixtimeModel

import unic


convert_model = unic.load_model("unixtime")

# Specify time zone (single value)
convert_unixtime = convert_model.convert("2023-05-12 10:15:20", tz="Asia/Tokyo")

# Specify unit(if not specified, the unit defaults to seconds)
convert_unixtime = convert_model.convert("2023-05-12 10:15:20.123", tz="Asia/Tokyo", unit="msec")

# Specify time zone (list)
convert_unixtime = convert_model.convert(["2023-05-12 10:15:20","2023-05-13 10:15:20","2023-05-14 10:15:20"], tz="Asia/Tokyo")

# Specify time zone (batch processing) -- deprecated
convert_unixtime = convert_model.convert_batch(["2023-05-12 10:15:20","2023-05-13 10:15:20","2023-05-14 10:15:20"], tz="Asia/Tokyo")

Length Unit

MetricSystemModel

import unic


convert_model = unic.load_model("metric_system")

# Convert cm to m (single value)
convert_m = convert_model.convert(20, from_unit="cm", to_unit="m")

# Convert cm to m (list)
convert_m = convert_model.conver([20,50,100,200], from_unit="cm", to_unit="m")

# Convert cm to m (batch processing)-- deprecated, will be removed in a future release
convert_m = convert_model.convert_batch([20,50,100,200], from_unit="cm", to_unit="m")

⚠️ Deprecation Notice

The convert_batch() method is now deprecated and will be removed in a future release.

You can now use the convert() method for both single values and lists.

Before (deprecated):

convert_model.convert_batch([2, 4, 6], from_unit="hour", to_unit="min")

Now (recommended):

convert_model.convert([2, 4, 6], from_unit="hour", to_unit="min")

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

unic-2.2.0.tar.gz (57.6 kB view details)

Uploaded Source

Built Distribution

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

unic-2.2.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file unic-2.2.0.tar.gz.

File metadata

  • Download URL: unic-2.2.0.tar.gz
  • Upload date:
  • Size: 57.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for unic-2.2.0.tar.gz
Algorithm Hash digest
SHA256 9b99094fb36140ca23ef20af7097b2c55c4cae872b34911ede31a1cb7e52d37a
MD5 20e6638fdecdbd93fc417971896db2da
BLAKE2b-256 bedfd1fef026db64b719f867fbe19da26eec608cdc10b74b8f1e6704b55ee456

See more details on using hashes here.

File details

Details for the file unic-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: unic-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for unic-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 056bc0fd16d7acf9a5ee752829ffd56573d0deec8d3d12aea6409625bd26f22f
MD5 03e8ca04ab1a0a7b7b717d037a423cf2
BLAKE2b-256 b65e448fd4bab281783ed1f1c813a91aef8ca040be312ee104e6059b4b6bdca2

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