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 IDname: Country nameiso2: 2-letter ISO codeiso3: 3-letter ISO codephone_code: International dialing codecapital: Capital cityflag_url: Flag image URLis_rtl: Right-to-left language flagcurrency_id: Associated currency ID
Currencies
Each currency object contains:
id: Internal IDname: Currency namecode: 3-letter ISO codesymbol: Currency symbol
Timezones
Each timezone object contains:
id: Internal IDiana_name: IANA timezone identifierdisplay_name: Human-readable nameabbreviation: Short abbreviationgmt_offset: GMT offset stringdst_offset: DST offset (if applicable)is_dst_active: DST statusis_active: Active status
Languages
Each language object contains:
id: Internal IDname: Language namecode: ISO 639-1 codecode_3: ISO 639-3 codenative_name: Native language nameis_rtl: Right-to-left flagscript: Writing system
Error Codes
Each error code object contains:
code: Error code stringhttp_status: HTTP status codecategory: Error categorymessage: Error messagedescription: Detailed descriptionis_retryable: Retry flagretry_after_seconds: Retry delay
API Reference
Countries API
get_all(): Get all countriesget_by_id(id): Get country by IDget_by_iso2(iso2): Get country by 2-letter ISO codeget_by_iso3(iso3): Get country by 3-letter ISO codeget_by_criteria(func): Filter countries by custom criteriasearch(query): Search countries by nameget_with_currencies(): Get countries with currency information
Currencies API
get_all(): Get all currenciesget_by_id(id): Get currency by IDget_by_code(code): Get currency by ISO codesearch(query): Search currencies by name or code
Timezones API
get_all(): Get all timezonesget_by_id(id): Get timezone by IDget_by_iana_name(name): Get timezone by IANA namesearch(query): Search timezones by name
Languages API
get_all(): Get all languagesget_by_id(id): Get language by IDget_by_code(code): Get language by ISO codesearch(query): Search languages by name
Error Codes API
get_all(): Get all error codesget_by_code(code): Get error code by codeget_by_category(category): Get error codes by categoryget_by_http_status(status): Get error codes by HTTP status
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dbbe1fed8783aef2bb8ef99d45ac4d210f88e848936aeab610d4d1e966c4e1e
|
|
| MD5 |
ce691775d981869322bd31fccc663dc4
|
|
| BLAKE2b-256 |
dd6f57ad2fb23cf81e278c52180a62919626d6687c382b525c63ca474890f0ae
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a76db6ebd6e386562f39070c555e8dad98490f41180467a44fd572d7d21df59b
|
|
| MD5 |
a73250ad8009781c5e6af0d64413295b
|
|
| BLAKE2b-256 |
d5f9f344af16ff651dde30772330fe56f2a099ada8d9530e7ecae3fac49b779b
|