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.0.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.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydiyanet-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 0d563e5f2f66d7df217f960162c7985c64f7ae43c814dc3e5cf4a684d488b22a
MD5 582d02e314f3d2b61b57a54a811792f3
BLAKE2b-256 71d1c6e938566365b28542055fa427bc89e30072d0c099ca93b5b870772ad468

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pydiyanet-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29e6928cc29ccfb43e62ec2521c624b7acb5cfe8646e1874acb0d9841ac4d8e0
MD5 15bbdda0464a35877c71cc846abd12c4
BLAKE2b-256 838f56b508f31e10a87247d12425de4f87f7753ad7eead68bd6eab1cd5febafe

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