Skip to main content

Lightweight Python library for time unit conversions and Unix timestamp conversion.

Project description

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

unic

unic is a lightweight Python library for time unit conversions and Unix timestamp conversions:

  • time units (hour, min, sec, msec)
  • Unix timestamps to datetime / date
  • datetime strings to Unix timestamps

It is designed for simple scripting, data processing, analytics, and timestamp handling.

Installation

pip install unic

Quick Start

import unic

# Time conversion
time_model = unic.load_model("time")
print(time_model.convert(2, from_unit="hour", to_unit="min"))  # 120

# Unixtime -> datetime
datetime_model = unic.load_model("datetime")
print(datetime_model.convert(1657985494, format="datetime"))

# String datetime -> unixtime
unixtime_model = unic.load_model("unixtime")
print(unixtime_model.convert("2022-07-18 13:49:00", tz="Asia/Tokyo"))

Supported Conversions

TimeModel

  • hour / min / sec / msec

DatetimeModel

  • unixtime -> datetime.datetime
  • unixtime -> datetime.date

UnixtimeModel

  • datetime string -> unixtime
  • supported formats:
    • yyyy-mm-dd hh:mm:ss
    • yyyy/mm/dd hh:mm:ss

Examples

Convert a single value

import unic

model = unic.load_model("time")
result = model.convert(7.5, from_unit="hour", to_unit="min")
print(result)  # 450

Convert a list of values

import unic

model = unic.load_model("time")
result = model.convert([2, 4, 6], from_unit="hour", to_unit="min")
print(result)  # [120, 240, 360]

Convert unixtime to datetime

import unic

model = unic.load_model("datetime")
result = model.convert(1657985494, format="datetime", tz="Asia/Tokyo")
print(result)

Convert datetime string to unixtime

import unic

model = unic.load_model("unixtime")
result = model.convert("2022-07-18 13:49:00.123", unit="msec")
print(result)

Notes

  • convert() supports both single values and lists.
  • convert_batch() is deprecated. Please use convert() with a list instead.
  • If unit is omitted in UnixtimeModel, the default is sec.

Documentation

  • See docs/UserGuide.md
  • Add future pages:
    • docs/QuickStart.md
    • docs/SupportedConversions.md
    • docs/FAQ.md
    • docs/MigrationGuide.md

Why unic?

  • Simple API
  • Lightweight package
  • Supports list conversion
  • Supports timezone-aware conversion
  • Tested with multiple Python versions

License

MIT

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-3.0.0.tar.gz (56.3 kB view details)

Uploaded Source

Built Distribution

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

unic-3.0.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: unic-3.0.0.tar.gz
  • Upload date:
  • Size: 56.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for unic-3.0.0.tar.gz
Algorithm Hash digest
SHA256 d05219f67f931a45228ba911b6d185d20bf38fa4a39e37cbe4351e9d6ef842cd
MD5 9a3280432916e9e581106392bdedda53
BLAKE2b-256 6c00f05a15500908b04289fc69517f85c1883e6cac789aa5bdc49878763a14a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for unic-3.0.0.tar.gz:

Publisher: publish-to-pypi.yml on subretu/unic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: unic-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for unic-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9590741d8fe6393c58f9912e7b4647a47327bd2d6c966a2ea79276f12ebaf210
MD5 7b2df05193b3ff7d6844179ed9141db7
BLAKE2b-256 f1abd0461734bc6214f5aaf607fadc4fd6230ca2498f7816c1553c13ae0e14f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for unic-3.0.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on subretu/unic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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