grutil
A Python utility library providing helper functions for working with Greek-specific formats, dates, numbers, and validators.
Features
📅 Date & Time Utilities (datetimes)
Convert between ISO 8601 and Greek date formats, and perform datetime operations:
iso2gr(iso_date_str)- Convert ISO date (YYYY-MM-DD) to Greek format (DD/MM/YYYY)gr2iso(gr_date)- Convert Greek date (DD/MM/YYYY) to ISO format (YYYY-MM-DD)date2gr(date_obj)- Convert Python date object to Greek format stringgr2date(gr_date)- Convert Greek date string to Python date objectiso2yearmonth(isodate)- Extract year-month from ISO date (2023-01-15 → 2023-01)is_greek_date(grdate)- Validate if string matches Greek date formatdelta_hours(date_from, date_to)- Calculate hours between two datetime objectsround_half(hours)- Round hours to nearest half hour
🔢 Number Utilities (numbers)
Handle Greek number formatting (using comma as decimal separator and period as thousands separator):
gr2float(gr_number_str)- Convert Greek-formatted number (1.234.567,89) to floatfloat2gr(number, decimals=2)- Convert float to Greek-formatted stringfloat2gr_empty_zero(number, decimals=2)- Convert float to Greek format, returns empty string for zero
📝 Text Utilities (texts)
Greek text processing utilities:
grup(text)- Normalize Greek text by converting to uppercase and removing accents/diacritics for comparison
✅ Validators (validators)
Validate Greek identification numbers:
is_valid_afm(afm)- Validate Greek VAT number (AFM - 9 digits)is_valid_amka(amka)- Validate Greek Social Security Number (AMKA - 11 digits)
Installation
pip install grutil
Or using uv:
uv add grutil
Usage Examples
Date Conversions
from grutil.datetimes import iso2gr, gr2iso, gr2date
# Convert ISO to Greek format
greek_date = iso2gr("2024-03-15") # Returns: "15/03/2024"
# Convert Greek to ISO format
iso_date = gr2iso("15/03/2024") # Returns: "2024-03-15"
# Convert Greek string to date object
date_obj = gr2date("15/03/2024") # Returns: datetime.date(2024, 3, 15)
Number Formatting
from grutil.numbers import gr2float, float2gr
# Parse Greek-formatted number
value = gr2float("1.234.567,89") # Returns: 1234567.89
# Format number as Greek
formatted = float2gr(1234567.89) # Returns: "1.234.567,89"
formatted = float2gr(1234.5, decimals=3) # Returns: "1.234,500"
Text Processing
from grutil.texts import grup
# Normalize Greek text for comparison
normalized = grup("Αθήνα") # Returns: "ΑΘΗΝΑ"
normalized = grup("Ελλάδα") # Returns: "ΕΛΛΑΔΑ"
# Useful for case-insensitive comparisons
if grup(user_input) == grup("ΑΘΉΝΑ"):
print("Match!")
Validators
from grutil.validators import is_valid_afm, is_valid_amka
# Validate Greek VAT number (AFM)
is_valid_afm("123456789") # Returns: True or False
# Validate Greek Social Security Number (AMKA)
is_valid_amka("12345678901") # Returns: True or False
Development
Requirements
- Python >= 3.10
- pytest >= 9.0.1 (for development)
Running Tests
pytest
License
This project is maintained by Ted Lazaros (tedlaz@gmail.com).
Metadata
Release files for grutil 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| grutil-0.6.0.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| grutil-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.4 kB
Release files / grutil-0.6.0.tar.gz
| Download URL | grutil-0.6.0.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09703b5347d7c7b846e38ff2f25e7d5decbc40a75f9cd2a46ff7f1784b03f3e1
|
|
BLAKE2b-256 checksum How to use checksums |
dae40718230919c929653653f1b52762add92c75f147ef5f01d183506aafcd29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / grutil-0.6.0-py3-none-any.whl
| Download URL | grutil-0.6.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2acf9e70520050379a2ef2a2790b5bee66704519c02a7dbc848bb9ce25dd2883
|
|
BLAKE2b-256 checksum How to use checksums |
d61f4df010b175b323a93d564989a566ad8499ccf66808325460f40d717f29d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|