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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydiyanet-0.1.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pydiyanet-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0c173735c086fabdce66b57243ef2867e5e0fbd0f31a2bb6c1f47a9e5af09e3b
MD5 7efd0eb9eb70b11e5084a55dbce0ffd7
BLAKE2b-256 3d1aae5dec27f006905ad43fae6a6e2f6227d54c6dd8bd15661696317bd8fa7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydiyanet-0.1.2.tar.gz:

Publisher: publish.yml on mahdemir/pydiyanet

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: pydiyanet-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pydiyanet-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2c2e0de4e3ff6df43b8767f55656188097140094287b77b634ab40a2be2efc35
MD5 621b2a41101d376699fd5630a2ddcb84
BLAKE2b-256 728eb8a3d5be291124ebe68e6d3fb755cdc6d6239e9af281427681e6257763b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydiyanet-0.1.2-py3-none-any.whl:

Publisher: publish.yml on mahdemir/pydiyanet

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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