Skip to main content

Python client for Diyanet prayer times API

Project description

pydiyanet

Python client library for the Diyanet prayer times API.

Features

  • Async/await support using aiohttp
  • Full type hints with py.typed for mypy compatibility
  • Authentication and token refresh handling
  • Access to prayer times, countries, states, and cities
  • Comprehensive error handling

Installation

pip install pydiyanet

Usage

import asyncio
from aiohttp import ClientSession
from pydiyanet import DiyanetApiClient, DiyanetAuthError, DiyanetConnectionError

async def main():
    async with ClientSession() as session:
        client = DiyanetApiClient(session, "your-email@example.com", "your-password")

        try:
            # Authenticate
            await client.authenticate()

            # Get prayer times for a location
            prayer_times = await client.get_prayer_times(location_id=9146)
            print(f"Fajr: {prayer_times['fajr']}")
            print(f"Dhuhr: {prayer_times['dhuhr']}")

            # Get countries
            countries = await client.get_countries()

            # Get states for a country
            states = await client.get_states(country_id=2)

            # Get cities for a state
            cities = await client.get_cities(state_id=9)

        except DiyanetAuthError as err:
            print(f"Authentication failed: {err}")
        except DiyanetConnectionError as err:
            print(f"Connection error: {err}")

asyncio.run(main())

API Reference

DiyanetApiClient

__init__(session: ClientSession, email: str, password: str)

Initialize the API client with an aiohttp session and credentials.

async authenticate() -> bool

Authenticate with the Diyanet API and obtain access/refresh tokens.

Raises:

  • DiyanetAuthError: If authentication fails
  • DiyanetConnectionError: If there's a network error

async get_prayer_times(location_id: int) -> dict[str, Any]

Get prayer times for a specific location.

Returns a dictionary containing prayer times for the current day.

async get_countries() -> list[dict[str, Any]]

Get list of all available countries.

async get_states(country_id: int) -> list[dict[str, Any]]

Get list of states for a given country.

async get_cities(state_id: int) -> list[dict[str, Any]]

Get list of cities for a given state.

async get_city_detail(city_id: int) -> dict[str, Any] | None

Get detailed information for a specific city.

Exceptions

  • DiyanetApiError: Base exception for all API errors
  • DiyanetAuthError: Raised when authentication fails
  • DiyanetConnectionError: Raised when there's a network/connection error

Token Management

The client automatically handles token expiration and refresh:

  • Access tokens expire after 30 minutes
  • Refresh tokens expire after 45 minutes
  • Tokens are automatically refreshed when needed
  • Full re-authentication occurs when refresh token expires

Requirements

  • Python 3.11+
  • aiohttp >= 3.9.0

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

pydiyanet-0.1.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

pydiyanet-0.1.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file pydiyanet-0.1.1.tar.gz.

File metadata

  • Download URL: pydiyanet-0.1.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pydiyanet-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a51fc8d04827288c5c9d4776810c6db6e2b06d997c317ebd6d46a1192d452757
MD5 c085f17cd4ebb2db07b21c9d217f0f61
BLAKE2b-256 c65b377187401fbb213c9eeb0351016dfad7f1af344d72043c5c3c21be61bc86

See more details on using hashes here.

File details

Details for the file pydiyanet-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pydiyanet-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pydiyanet-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6e30353d9ba9132e69380a267730484c428c335f4ef099e55133efe2058c79ad
MD5 b54de02ea421a8b91bcd66f4429ba840
BLAKE2b-256 78e187dbcbf5f58dd73441dca82cb633e3c87c36ab219b0a9a1114ccff412268

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