Skip to content

Integrations

Each integration needs its extra, e.g. pip install "cedikit[pandas]".

cedikit.integrations.pandas_accessor

A .cedikit accessor for pandas Series.

Importing this module registers the accessor::

import cedikit.integrations.pandas_accessor  # noqa: F401

df["phone"] = df["phone"].cedikit.normalise()          # invalid -> None
df["amount"] = df["amount"].cedikit.parse_money()      # Decimal, invalid -> None
df["network"] = df["phone"].cedikit.likely_network()

CedikitAccessor

normalise()

Phone numbers in E.164; invalid entries become None.

parse_money()

Exact Decimal amounts; invalid entries (and floats) become None.

Read money columns as text (dtype=str) so floats never appear.

cedikit.integrations.pydantic_types

Pydantic field types, for FastAPI and data validation.

Example::

from pydantic import BaseModel
from cedikit.integrations.pydantic_types import CediAmount, GhanaPhone

class Order(BaseModel):
    customer: GhanaPhone      # "024 412 3456" -> "+233244123456"
    total: CediAmount         # "GH₵1,200.5"   -> Decimal("1200.50"); floats rejected

GhanaPhone = Annotated[str, BeforeValidator(_wrap(phone.normalise))] module-attribute

A Ghanaian mobile number, stored in E.164 form.

CediAmount = Annotated[Decimal, BeforeValidator(_wrap(money.parse))] module-attribute

A cedi amount rounded to the pesewa. Floats are rejected.

GhanaCardNumber = Annotated[str, AfterValidator(_wrap(ghana_card.normalise))] module-attribute

A Ghana Card number in GHA-XXXXXXXXX-X form (format check only).

DigitalAddress = Annotated[str, AfterValidator(_wrap(lambda v: gpgps.parse(v).code))] module-attribute

A GhanaPostGPS address such as AK-039-5028 (format check only).

cedikit.integrations.django_validators

Validators for Django models and forms.

Example::

from django.db import models
from cedikit.integrations.django_validators import validate_ghana_phone

class Customer(models.Model):
    phone = models.CharField(max_length=20, validators=[validate_ghana_phone])

Validators only check; use :func:cedikit.phone.normalise in clean() to store numbers in one consistent format.

cedikit.integrations.flask_validators

WTForms validators, for Flask-WTF forms.

Example::

from flask_wtf import FlaskForm
from wtforms import StringField
from cedikit.integrations.flask_validators import CediAmount, GhanaPhone

class PaymentForm(FlaskForm):
    phone = StringField("Phone", validators=[GhanaPhone()])
    amount = StringField("Amount", validators=[CediAmount()])