quran-foundation-api 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: [main]
7
+
8
+ jobs:
9
+ verify:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-python@v5
17
+ with:
18
+ python-version: ${{ matrix.python-version }}
19
+ cache: pip
20
+ - run: python -m pip install --upgrade pip
21
+ - run: python -m pip install -e ".[dev]"
22
+ - run: ruff check .
23
+ - run: pytest
24
+ - run: python -m build
25
+ - run: twine check dist/*
@@ -0,0 +1,63 @@
1
+ name: Publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+ inputs:
8
+ target:
9
+ description: Package index to publish
10
+ required: true
11
+ type: choice
12
+ default: testpypi
13
+ options:
14
+ - testpypi
15
+ - pypi
16
+
17
+ permissions:
18
+ contents: read
19
+ id-token: write
20
+
21
+ jobs:
22
+ build:
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+ - uses: actions/setup-python@v5
27
+ with:
28
+ python-version: '3.12'
29
+ cache: pip
30
+ - run: python -m pip install --upgrade pip
31
+ - run: python -m pip install build twine
32
+ - run: python -m build
33
+ - run: twine check dist/*
34
+ - uses: actions/upload-artifact@v4
35
+ with:
36
+ name: dist
37
+ path: dist/*
38
+
39
+ publish-testpypi:
40
+ needs: build
41
+ if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.target == 'testpypi')
42
+ runs-on: ubuntu-latest
43
+ environment: testpypi
44
+ steps:
45
+ - uses: actions/download-artifact@v4
46
+ with:
47
+ name: dist
48
+ path: dist
49
+ - uses: pypa/gh-action-pypi-publish@release/v1
50
+ with:
51
+ repository-url: https://test.pypi.org/legacy/
52
+
53
+ publish-pypi:
54
+ needs: build
55
+ if: github.event_name == 'workflow_dispatch' && inputs.target == 'pypi'
56
+ runs-on: ubuntu-latest
57
+ environment: pypi
58
+ steps:
59
+ - uses: actions/download-artifact@v4
60
+ with:
61
+ name: dist
62
+ path: dist
63
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,9 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+ .DS_Store
@@ -0,0 +1,8 @@
1
+ # Agent Instructions
2
+
3
+ Keep the Python SDK small, explicit, and server-safe.
4
+
5
+ - Do not expose OAuth client secrets or tokens in examples intended for browsers.
6
+ - Prefer stable sync APIs before adding async variants.
7
+ - Keep public package docs accurate for PyPI users.
8
+ - Verify with ruff, pytest, build, and twine check before release.
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Initial Python SDK with sync client and OAuth2 helpers.
6
+ - Added explicit helpers for core Content, Search, and signed-in User API workflows.
7
+ - Added service request helpers for Content, Search, and User endpoints that do not yet have dedicated methods.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Quran Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: quran-foundation-api
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for Quran Foundation APIs.
5
+ Project-URL: Homepage, https://api-docs.quran.foundation/docs/sdk/python/
6
+ Project-URL: Documentation, https://api-docs.quran.foundation/docs/sdk/python/
7
+ Project-URL: Repository, https://github.com/quran/api-python
8
+ Project-URL: Issues, https://github.com/quran/api-python/issues
9
+ Author-email: Quran Foundation <developers@quran.foundation>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: api,oauth2,quran,quran-foundation,sdk
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.9
26
+ Requires-Dist: httpx<1,>=0.27
27
+ Provides-Extra: dev
28
+ Requires-Dist: build>=1.2; extra == 'dev'
29
+ Requires-Dist: pytest>=8.0; extra == 'dev'
30
+ Requires-Dist: ruff>=0.8; extra == 'dev'
31
+ Requires-Dist: twine>=6.0; extra == 'dev'
32
+ Provides-Extra: fastapi
33
+ Requires-Dist: fastapi>=0.115; extra == 'fastapi'
34
+ Requires-Dist: uvicorn>=0.30; extra == 'fastapi'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # quran-foundation-api
38
+
39
+ Official Python SDK for Quran Foundation APIs.
40
+
41
+ ```bash
42
+ pip install quran-foundation-api
43
+ ```
44
+
45
+ ```python
46
+ from quran_foundation import QuranClient
47
+
48
+ client = QuranClient(client_id="YOUR_CLIENT_ID", access_token="ACCESS_TOKEN")
49
+ chapters = client.list_chapters()
50
+ print(chapters)
51
+ ```
52
+
53
+ ## Content and search
54
+
55
+ ```python
56
+ from quran_foundation import QuranClient
57
+
58
+ client = QuranClient(client_id="YOUR_CLIENT_ID", access_token="ACCESS_TOKEN")
59
+
60
+ chapter = client.get_chapter(1)
61
+ verses = client.get_verses_by_range("1:1", "1:7", translations="131")
62
+ translations = client.list_translations()
63
+ results = client.search("mercy", mode="advanced", params={"size": 10})
64
+ ```
65
+
66
+ For endpoints that do not yet have a dedicated helper, use the service request helpers:
67
+
68
+ ```python
69
+ client.content_request("/verses/by_page/1", params={"translations": "131"})
70
+ client.search_request("/api/v1/search", params={"query": "mercy", "mode": "quick"})
71
+ client.user_request("/bookmarks", params={"page": 1})
72
+ ```
73
+
74
+ ## User APIs
75
+
76
+ Use signed-in User API helpers with a user access token. Keep the token server-side.
77
+
78
+ ```python
79
+ profile = client.get_profile()
80
+ bookmarks = client.list_bookmarks()
81
+ client.create_bookmark({"verse_key": "2:255", "mushaf_id": 1})
82
+ client.update_preference({"key": "theme", "value": "dark"})
83
+ ```
84
+
85
+ ## OAuth2 helpers
86
+
87
+ Use OAuth helpers on the server side. Never expose `client_secret`, access tokens, or refresh tokens to browser code.
88
+
89
+ ```python
90
+ from quran_foundation.oauth import build_authorization_url, create_pkce_pair, exchange_code
91
+
92
+ verifier, challenge = create_pkce_pair()
93
+ authorize_url = build_authorization_url(
94
+ client_id="YOUR_CLIENT_ID",
95
+ redirect_uri="https://your-app.com/callback",
96
+ scope="openid offline_access user bookmark",
97
+ state="random-state",
98
+ code_challenge=challenge,
99
+ )
100
+
101
+ tokens = exchange_code(
102
+ client_id="YOUR_CLIENT_ID",
103
+ client_secret="YOUR_CLIENT_SECRET",
104
+ code="CODE_FROM_CALLBACK",
105
+ code_verifier=verifier,
106
+ redirect_uri="https://your-app.com/callback",
107
+ )
108
+ ```
109
+
110
+ ## Development
111
+
112
+ ```bash
113
+ python -m pip install -e ".[dev]"
114
+ ruff check .
115
+ pytest
116
+ python -m build
117
+ twine check dist/*
118
+ ```
@@ -0,0 +1,82 @@
1
+ # quran-foundation-api
2
+
3
+ Official Python SDK for Quran Foundation APIs.
4
+
5
+ ```bash
6
+ pip install quran-foundation-api
7
+ ```
8
+
9
+ ```python
10
+ from quran_foundation import QuranClient
11
+
12
+ client = QuranClient(client_id="YOUR_CLIENT_ID", access_token="ACCESS_TOKEN")
13
+ chapters = client.list_chapters()
14
+ print(chapters)
15
+ ```
16
+
17
+ ## Content and search
18
+
19
+ ```python
20
+ from quran_foundation import QuranClient
21
+
22
+ client = QuranClient(client_id="YOUR_CLIENT_ID", access_token="ACCESS_TOKEN")
23
+
24
+ chapter = client.get_chapter(1)
25
+ verses = client.get_verses_by_range("1:1", "1:7", translations="131")
26
+ translations = client.list_translations()
27
+ results = client.search("mercy", mode="advanced", params={"size": 10})
28
+ ```
29
+
30
+ For endpoints that do not yet have a dedicated helper, use the service request helpers:
31
+
32
+ ```python
33
+ client.content_request("/verses/by_page/1", params={"translations": "131"})
34
+ client.search_request("/api/v1/search", params={"query": "mercy", "mode": "quick"})
35
+ client.user_request("/bookmarks", params={"page": 1})
36
+ ```
37
+
38
+ ## User APIs
39
+
40
+ Use signed-in User API helpers with a user access token. Keep the token server-side.
41
+
42
+ ```python
43
+ profile = client.get_profile()
44
+ bookmarks = client.list_bookmarks()
45
+ client.create_bookmark({"verse_key": "2:255", "mushaf_id": 1})
46
+ client.update_preference({"key": "theme", "value": "dark"})
47
+ ```
48
+
49
+ ## OAuth2 helpers
50
+
51
+ Use OAuth helpers on the server side. Never expose `client_secret`, access tokens, or refresh tokens to browser code.
52
+
53
+ ```python
54
+ from quran_foundation.oauth import build_authorization_url, create_pkce_pair, exchange_code
55
+
56
+ verifier, challenge = create_pkce_pair()
57
+ authorize_url = build_authorization_url(
58
+ client_id="YOUR_CLIENT_ID",
59
+ redirect_uri="https://your-app.com/callback",
60
+ scope="openid offline_access user bookmark",
61
+ state="random-state",
62
+ code_challenge=challenge,
63
+ )
64
+
65
+ tokens = exchange_code(
66
+ client_id="YOUR_CLIENT_ID",
67
+ client_secret="YOUR_CLIENT_SECRET",
68
+ code="CODE_FROM_CALLBACK",
69
+ code_verifier=verifier,
70
+ redirect_uri="https://your-app.com/callback",
71
+ )
72
+ ```
73
+
74
+ ## Development
75
+
76
+ ```bash
77
+ python -m pip install -e ".[dev]"
78
+ ruff check .
79
+ pytest
80
+ python -m build
81
+ twine check dist/*
82
+ ```
@@ -0,0 +1,5 @@
1
+ from quran_foundation import QuranClient
2
+
3
+ client = QuranClient(client_id="YOUR_CLIENT_ID", access_token="ACCESS_TOKEN")
4
+ print(client.list_chapters())
5
+ print(client.search("mercy"))
@@ -0,0 +1,26 @@
1
+ from fastapi import FastAPI, HTTPException, Request
2
+
3
+ from quran_foundation.oauth import exchange_code
4
+
5
+ app = FastAPI()
6
+
7
+ CLIENT_ID = "YOUR_CLIENT_ID"
8
+ CLIENT_SECRET = "YOUR_CLIENT_SECRET"
9
+ REDIRECT_URI = "http://localhost:8000/callback"
10
+
11
+
12
+ @app.get("/callback")
13
+ def callback(request: Request, code: str, state: str):
14
+ code_verifier = request.session.get("code_verifier") if hasattr(request, "session") else None
15
+ expected_state = request.session.get("state") if hasattr(request, "session") else None
16
+
17
+ if not code_verifier or state != expected_state:
18
+ raise HTTPException(status_code=400, detail="Invalid OAuth state")
19
+
20
+ return exchange_code(
21
+ client_id=CLIENT_ID,
22
+ client_secret=CLIENT_SECRET,
23
+ code=code,
24
+ code_verifier=code_verifier,
25
+ redirect_uri=REDIRECT_URI,
26
+ )
@@ -0,0 +1,63 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.26"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "quran-foundation-api"
7
+ version = "0.1.0"
8
+ description = "Official Python SDK for Quran Foundation APIs."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "Quran Foundation", email = "developers@quran.foundation" }
14
+ ]
15
+ keywords = ["quran", "quran-foundation", "api", "sdk", "oauth2"]
16
+ dependencies = [
17
+ "httpx>=0.27,<1"
18
+ ]
19
+ classifiers = [
20
+ "Development Status :: 3 - Alpha",
21
+ "Intended Audience :: Developers",
22
+ "License :: OSI Approved :: MIT License",
23
+ "Programming Language :: Python :: 3",
24
+ "Programming Language :: Python :: 3 :: Only",
25
+ "Programming Language :: Python :: 3.9",
26
+ "Programming Language :: Python :: 3.10",
27
+ "Programming Language :: Python :: 3.11",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Programming Language :: Python :: 3.13",
30
+ "Typing :: Typed",
31
+ "Topic :: Software Development :: Libraries :: Python Modules"
32
+ ]
33
+
34
+ [project.optional-dependencies]
35
+ dev = [
36
+ "build>=1.2",
37
+ "pytest>=8.0",
38
+ "ruff>=0.8",
39
+ "twine>=6.0"
40
+ ]
41
+ fastapi = [
42
+ "fastapi>=0.115",
43
+ "uvicorn>=0.30"
44
+ ]
45
+
46
+ [project.urls]
47
+ Homepage = "https://api-docs.quran.foundation/docs/sdk/python/"
48
+ Documentation = "https://api-docs.quran.foundation/docs/sdk/python/"
49
+ Repository = "https://github.com/quran/api-python"
50
+ Issues = "https://github.com/quran/api-python/issues"
51
+
52
+ [tool.hatch.build.targets.wheel]
53
+ packages = ["src/quran_foundation"]
54
+
55
+ [tool.pytest.ini_options]
56
+ testpaths = ["tests"]
57
+
58
+ [tool.ruff]
59
+ line-length = 100
60
+ target-version = "py39"
61
+
62
+ [tool.ruff.lint]
63
+ select = ["E", "F", "I", "UP", "B"]
@@ -0,0 +1,14 @@
1
+ """Quran Foundation Python SDK."""
2
+
3
+ from .client import QuranClient
4
+ from .errors import QuranApiError, QuranAuthError, QuranHttpError
5
+
6
+ __version__ = "0.1.0"
7
+
8
+ __all__ = [
9
+ "QuranApiError",
10
+ "QuranAuthError",
11
+ "QuranClient",
12
+ "QuranHttpError",
13
+ "__version__",
14
+ ]