Lightweight Python package for converting.
Project description
unic
unic is a lightweight Python package for converting:
- time units (
hour,min,sec,msec) - Unix timestamps to
datetime/date - datetime strings to Unix timestamps
- metric length units (
nmtoTm)
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"))
# Metric system conversion
metric_model = unic.load_model("metric_system")
print(metric_model.convert(1200, from_unit="mm", to_unit="m")) # 1.2
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:ssyyyy/mm/dd hh:mm:ss
MetricSystemModel
- metric length units:
nm,um,mm,cm,m,km,Mm,Gm,Tm
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 useconvert()with a list instead.- If
unitis omitted inUnixtimeModel, the default issec.
Documentation
- See
docs/UserGuide.md - Add future pages:
docs/QuickStart.mddocs/SupportedConversions.mddocs/FAQ.mddocs/MigrationGuide.md
Why unic?
- Simple API
- Lightweight package
- Supports list conversion
- Supports timezone-aware conversion
- Tested with multiple Python versions
License
MIT
Project details
Release history Release notifications | RSS feed
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 unic-2.2.2.tar.gz.
File metadata
- Download URL: unic-2.2.2.tar.gz
- Upload date:
- Size: 58.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ff508ed2672b7cef6e51fcc9e122de89c2c96e22839b55f56febf7eebdacc57
|
|
| MD5 |
eebb0a2a6a5cd728b0d71c74cd17b93a
|
|
| BLAKE2b-256 |
81637b60e49dfd0afe40c393669513ccad3c86ddc386399622fc4a78797dda76
|
Provenance
The following attestation bundles were made for unic-2.2.2.tar.gz:
Publisher:
publish-to-pypi.yml on subretu/unic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unic-2.2.2.tar.gz -
Subject digest:
8ff508ed2672b7cef6e51fcc9e122de89c2c96e22839b55f56febf7eebdacc57 - Sigstore transparency entry: 1102474685
- Sigstore integration time:
-
Permalink:
subretu/unic@e78b612f32ca04a9033eb516486097503bec7e2d -
Branch / Tag:
refs/tags/2.2.2 - Owner: https://github.com/subretu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@e78b612f32ca04a9033eb516486097503bec7e2d -
Trigger Event:
release
-
Statement type:
File details
Details for the file unic-2.2.2-py3-none-any.whl.
File metadata
- Download URL: unic-2.2.2-py3-none-any.whl
- Upload date:
- Size: 15.0 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 |
dc5d61808af9b9a77f5bd2f0d1f03596ea4c64d68f820a6402e4427083208451
|
|
| MD5 |
de6babba9ef3d9dd81c235fd8bfd94ce
|
|
| BLAKE2b-256 |
db22bb403d459f1418b749758af28d327b6f5cb5ac6968ac0d559a97347ca71e
|
Provenance
The following attestation bundles were made for unic-2.2.2-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on subretu/unic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unic-2.2.2-py3-none-any.whl -
Subject digest:
dc5d61808af9b9a77f5bd2f0d1f03596ea4c64d68f820a6402e4427083208451 - Sigstore transparency entry: 1102474717
- Sigstore integration time:
-
Permalink:
subretu/unic@e78b612f32ca04a9033eb516486097503bec7e2d -
Branch / Tag:
refs/tags/2.2.2 - Owner: https://github.com/subretu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@e78b612f32ca04a9033eb516486097503bec7e2d -
Trigger Event:
release
-
Statement type: