Skip to main content

Add your description here

Project description

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 string
  • gr2date(gr_date) - Convert Greek date string to Python date object
  • iso2yearmonth(isodate) - Extract year-month from ISO date (2023-01-15 → 2023-01)
  • is_greek_date(grdate) - Validate if string matches Greek date format
  • delta_hours(date_from, date_to) - Calculate hours between two datetime objects
  • round_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 float
  • float2gr(number, decimals=2) - Convert float to Greek-formatted string
  • float2gr_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).

Version

Current version: 0.2.0

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

grutil-0.4.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

grutil-0.4.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file grutil-0.4.0.tar.gz.

File metadata

  • Download URL: grutil-0.4.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for grutil-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b4b6afb67ea61a15fdda932d1a3a8ddc1759b0bf144fe0a9b050e4c3d0634694
MD5 cd95a6b9bb406f194579c7a24ff8265c
BLAKE2b-256 49f04148fc47c8af52f8ec80961a859534bc0742cd4c68221c6accceac316b9b

See more details on using hashes here.

File details

Details for the file grutil-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: grutil-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for grutil-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca75153912eda876d42ed3acbd22f61350928b474c7f86baa1a410ac3536e1a5
MD5 f503da3c328ff5bf54a1bcd403f7693c
BLAKE2b-256 e84e0134d0cf0d264cafee7c4913ceac2c049e11f099044497ba67088a5f60d3

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