Skip to main content

Kite Common Python Package

Project description

Kite Common

A Python package providing common data and utilities for Kite applications. This package contains standardized data for countries, currencies, timezones, languages, and error codes that can be used across different frameworks and applications.

Features

  • Framework Agnostic: Works with any Python framework (Django, Flask, FastAPI, etc.)
  • Standardized Data: Pre-loaded with comprehensive country, currency, timezone, and language data
  • Error Code Management: Centralized error code definitions with HTTP status codes and categories
  • Easy Integration: Simple API for accessing and using the data
  • Memory Efficient: Lazy loading of data when needed

Installation

pip install kite-common

Or install from source:

git clone <repository-url>
cd kite-common
pip install -e .

Usage

Basic Usage

from kite_common import countries, currencies, timezones, languages, error_codes

# Get all countries
all_countries = countries.get_all()

# Get country by ID
us = countries.get_by_id(235)  # United States

# Get countries by ISO code
us_by_iso2 = countries.get_by_iso2('US')
us_by_iso3 = countries.get_by_iso3('USA')

# Get all currencies
all_currencies = currencies.get_all()

# Get currency by code
usd = currencies.get_by_code('USD')

# Get all timezones
all_timezones = timezones.get_all()

# Get timezone by IANA name
est = timezones.get_by_iana_name('America/New_York')

# Get all languages
all_languages = languages.get_all()

# Get language by code
english = languages.get_by_code('en')

# Get all error codes
all_errors = error_codes.get_all()

# Get error code by code
not_found = error_codes.get_by_code('USER_NOT_FOUND')

Advanced Usage

from kite_common import countries, currencies

# Filter countries
european_countries = countries.get_by_criteria(lambda c: c.get('is_rtl') == False)

# Get countries with their currencies (joined data)
countries_with_currencies = countries.get_with_currencies()

# Search countries
search_results = countries.search('United')

# Get error codes by category
auth_errors = error_codes.get_by_category('AUTHENTICATION')
validation_errors = error_codes.get_by_category('VALIDATION')

Integration Examples

FastAPI

from fastapi import FastAPI, HTTPException
from kite_common import countries, error_codes

app = FastAPI()

@app.get("/countries")
def get_countries():
    return {"countries": countries.get_all()}

@app.get("/countries/{country_id}")
def get_country(country_id: int):
    country = countries.get_by_id(country_id)
    if not country:
        error = error_codes.get_by_code('RESOURCE_NOT_FOUND')
        raise HTTPException(status_code=error['http_status'], detail=error['message'])
    return country

Django

from django.http import JsonResponse
from kite_common import countries

def countries_view(request):
    countries_data = countries.get_all()
    return JsonResponse({'countries': countries_data})

Flask

from flask import Flask, jsonify
from kite_common import countries

app = Flask(__name__)

@app.route('/countries')
def get_countries():
    return jsonify(countries.get_all())

Data Structure

Countries

Each country object contains:

  • id: Internal ID
  • name: Country name
  • iso2: 2-letter ISO code
  • iso3: 3-letter ISO code
  • phone_code: International dialing code
  • capital: Capital city
  • flag_url: Flag image URL
  • is_rtl: Right-to-left language flag
  • currency_id: Associated currency ID

Currencies

Each currency object contains:

  • id: Internal ID
  • name: Currency name
  • code: 3-letter ISO code
  • symbol: Currency symbol

Timezones

Each timezone object contains:

  • id: Internal ID
  • iana_name: IANA timezone identifier
  • display_name: Human-readable name
  • abbreviation: Short abbreviation
  • gmt_offset: GMT offset string
  • dst_offset: DST offset (if applicable)
  • is_dst_active: DST status
  • is_active: Active status

Languages

Each language object contains:

  • id: Internal ID
  • name: Language name
  • code: ISO 639-1 code
  • code_3: ISO 639-3 code
  • native_name: Native language name
  • is_rtl: Right-to-left flag
  • script: Writing system

Error Codes

Each error code object contains:

  • code: Error code string
  • http_status: HTTP status code
  • category: Error category
  • message: Error message
  • description: Detailed description
  • is_retryable: Retry flag
  • retry_after_seconds: Retry delay

API Reference

Countries API

  • get_all(): Get all countries
  • get_by_id(id): Get country by ID
  • get_by_iso2(iso2): Get country by 2-letter ISO code
  • get_by_iso3(iso3): Get country by 3-letter ISO code
  • get_by_criteria(func): Filter countries by custom criteria
  • search(query): Search countries by name
  • get_with_currencies(): Get countries with currency information

Currencies API

  • get_all(): Get all currencies
  • get_by_id(id): Get currency by ID
  • get_by_code(code): Get currency by ISO code
  • search(query): Search currencies by name or code

Timezones API

  • get_all(): Get all timezones
  • get_by_id(id): Get timezone by ID
  • get_by_iana_name(name): Get timezone by IANA name
  • search(query): Search timezones by name

Languages API

  • get_all(): Get all languages
  • get_by_id(id): Get language by ID
  • get_by_code(code): Get language by ISO code
  • search(query): Search languages by name

Error Codes API

  • get_all(): Get all error codes
  • get_by_code(code): Get error code by code
  • get_by_category(category): Get error codes by category
  • get_by_http_status(status): Get error codes by HTTP status

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

MIT License - see LICENSE file for details

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

kite_common_py-0.0.1.tar.gz (32.8 kB view details)

Uploaded Source

Built Distribution

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

kite_common_py-0.0.1-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

Details for the file kite_common_py-0.0.1.tar.gz.

File metadata

  • Download URL: kite_common_py-0.0.1.tar.gz
  • Upload date:
  • Size: 32.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for kite_common_py-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3dbbe1fed8783aef2bb8ef99d45ac4d210f88e848936aeab610d4d1e966c4e1e
MD5 ce691775d981869322bd31fccc663dc4
BLAKE2b-256 dd6f57ad2fb23cf81e278c52180a62919626d6687c382b525c63ca474890f0ae

See more details on using hashes here.

File details

Details for the file kite_common_py-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: kite_common_py-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 33.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for kite_common_py-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a76db6ebd6e386562f39070c555e8dad98490f41180467a44fd572d7d21df59b
MD5 a73250ad8009781c5e6af0d64413295b
BLAKE2b-256 d5f9f344af16ff651dde30772330fe56f2a099ada8d9530e7ecae3fac49b779b

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