Skip to content

Commit 8e91a87

Browse files
committed
- Intial commit
1 parent ad1cda0 commit 8e91a87

42 files changed

Lines changed: 1661 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/coverage.svg‎

Lines changed: 20 additions & 0 deletions
Loading

‎.github/workflows/run-tests.yml‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
tests:
16+
runs-on: ${{ matrix.os }}
17+
18+
strategy:
19+
fail-fast: true
20+
matrix:
21+
os: [ubuntu-latest]
22+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
23+
24+
name: Python ${{ matrix.python-version }} - ${{ matrix.os }}
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
30+
- name: Setup Python
31+
uses: actions/setup-python@v5
32+
with:
33+
python-version: ${{ matrix.python-version }}
34+
35+
- name: Install dependencies
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install -e ".[test]"
39+
40+
- name: Execute tests
41+
run: |
42+
pytest --cov=dhivehigpt_sdk --cov-report=xml --cov-report=term-missing
43+
44+
- name: Make code coverage badge
45+
if: startsWith(github.event.head_commit.message, 'coverage') && matrix.python-version == '3.13' && matrix.os == 'ubuntu-latest'
46+
run: |
47+
pip install genbadge[coverage]
48+
genbadge coverage -i coverage.xml -o .github/coverage.svg
49+
50+
- name: Commit code coverage badge
51+
if: startsWith(github.event.head_commit.message, 'coverage') && matrix.python-version == '3.13' && matrix.os == 'ubuntu-latest'
52+
run: |
53+
git config --local user.email "action@github.com"
54+
git config --local user.name "GitHub Action"
55+
git add .github/coverage.svg
56+
git diff --staged --quiet || git commit -m "Update coverage badge [skip ci]"
57+
git push

‎.idea/.gitignore‎

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/dhivehigpt-sdk.iml‎

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/inspectionProfiles/profiles_settings.xml‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/modules.xml‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/vcs.xml‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎CHANGELOG.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
3+
All notable changes to `dhivehigpt-sdk` will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.1.0] - 2026-08-21
11+
12+
### Added
13+
14+
- Initial release of the DhivehiGPT SDK for Python.
15+
- `DhivehiGPT` client with API key resolution from the `DHIVEHIGPT_API_KEY` environment variable.
16+
- `voices`, `tts`, `balance`, and `tasks` resources covering the full DhivehiGPT API.
17+
- Typed exception hierarchy (`AuthenticationError`, `PermissionDeniedError`, `NotFoundError`, `ValidationError`, `RateLimitError`, `ServerError`, `APIConnectionError`, `APIError`).

‎CONTRIBUTING.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Contributing
2+
3+
Contributions are welcome and will be fully credited.
4+
5+
## Pull Requests
6+
7+
- **Add tests** — your patch won't be accepted if it doesn't have tests.
8+
- **Document any change in behaviour** — make sure the `README.md` and any relevant files in `docs/` are kept up to date.
9+
- **Create feature branches** — don't ask us to pull from your `main` branch.
10+
- **One pull request per feature** — if you want to do more than one thing, send multiple pull requests.
11+
- **Send coherent history** — make sure each individual commit in your pull request is meaningful.
12+
13+
## Running Tests
14+
15+
```bash
16+
pip install -e ".[test]"
17+
pytest --cov=dhivehigpt_sdk --cov-report=term-missing
18+
```
19+
20+
**Happy coding**!

‎README.md‎

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# DhivehiGPT SDK for Python
2+
3+
[![Latest Version on PyPI](https://img.shields.io/pypi/v/dhivehigpt-sdk.svg?style=flat-square)](https://pypi.org/project/dhivehigpt-sdk/)
4+
[![Test Status](../../actions/workflows/run-tests.yml/badge.svg)](../../actions/workflows/run-tests.yml)
5+
![Code Coverage Badge](./.github/coverage.svg)
6+
[![Total Downloads](https://img.shields.io/pypi/dm/dhivehigpt-sdk.svg?style=flat-square)](https://pypi.org/project/dhivehigpt-sdk/)
7+
8+
A lightweight, zero-dependency Python SDK for the [DhivehiGPT API](https://dhivehigpt.com/docs).
9+
10+
## Requirements
11+
12+
- Python 3.8 or higher
13+
- No runtime dependencies — the SDK only uses the Python standard library.
14+
15+
## Installation
16+
17+
```bash
18+
pip install dhivehigpt-sdk
19+
```
20+
21+
## Getting an API key
22+
23+
API keys are generated from your DhivehiGPT team's [API Keys](https://dhivehigpt.com/team/api-keys) page. You'll need:
24+
25+
- A DhivehiGPT team account with an **active subscription**.
26+
- To be a **team owner** or **team admin** — only owners and admins can generate API keys.
27+
28+
## Quick start
29+
30+
The client reads the API key from the `DHIVEHIGPT_API_KEY` environment variable by default:
31+
32+
```bash
33+
export DHIVEHIGPT_API_KEY="your-api-key"
34+
```
35+
36+
```python
37+
from dhivehigpt_sdk import DhivehiGPT
38+
39+
client = DhivehiGPT()
40+
41+
# or pass the API key explicitly
42+
client = DhivehiGPT(api_key="your-api-key")
43+
```
44+
45+
`base_url` and `api_version` are optional and default to `https://api.dhivehigpt.com` and `v1`:
46+
47+
```python
48+
client = DhivehiGPT(
49+
api_key="your-api-key",
50+
base_url="https://api.dhivehigpt.com",
51+
api_version="v1",
52+
)
53+
```
54+
55+
## Usage
56+
57+
### Voices
58+
59+
```python
60+
voices = client.voices.list(gender="female", is_premium=False)
61+
voice = client.voices.get("hajja")
62+
```
63+
64+
### Text-to-Speech (TTS)
65+
66+
```python
67+
audio = client.tts.generate(text="ދިވެހިޖީޕީޓީއަށް މަރުޙަބާ", voice="hajja")
68+
69+
audios = client.tts.list(voice="hajja", per_page=20)
70+
one = client.tts.get(audio["data"]["uuid"])
71+
client.tts.update(audio["data"]["uuid"], title="Welcome message")
72+
client.tts.delete(audio["data"]["uuid"])
73+
```
74+
75+
### Balance
76+
77+
```python
78+
balance = client.balance.get()
79+
print(balance["billing_period"]["balance"])
80+
```
81+
82+
### Tasks
83+
84+
```python
85+
tasks = client.tasks.list(platform="tts")
86+
task = client.tasks.get("audio_generation")
87+
cost = client.tasks.calculate(task="audio_generation", units=1000)
88+
```
89+
90+
## Error handling
91+
92+
All errors raised by the SDK inherit from `dhivehigpt_sdk.DhivehiGPTError`:
93+
94+
```python
95+
from dhivehigpt_sdk import DhivehiGPT, DhivehiGPTError, NotFoundError
96+
97+
client = DhivehiGPT()
98+
99+
try:
100+
client.voices.get("does-not-exist")
101+
except NotFoundError as e:
102+
print(e.status_code, e.message)
103+
except DhivehiGPTError as e:
104+
print("Something else went wrong:", e)
105+
```
106+
107+
| Exception | Cause |
108+
|--------------------------|-----------------------------------------------------|
109+
| `AuthenticationError` | Missing, invalid, or revoked API key (401) |
110+
| `PermissionDeniedError` | Not enough credits, etc. (403) |
111+
| `NotFoundError` | Resource does not exist (404) |
112+
| `ValidationError` | Invalid request data (422); see `error.errors` |
113+
| `RateLimitError` | Exceeded 60 requests/minute per API key (429) |
114+
| `ServerError` | Upstream error (5xx) |
115+
| `APIConnectionError` | Could not reach the API |
116+
117+
## Documentation
118+
119+
Full documentation is available at [https://docs.javaabu.com/docs/dhivehigpt-sdk-python](https://docs.javaabu.com/docs/dhivehigpt-sdk-python).
120+
121+
The full DhivehiGPT API reference is available at [https://dhivehigpt.com/docs](https://dhivehigpt.com/docs).
122+
123+
Find yourself stuck using the package? Found a bug? Do you have general questions or suggestions? Feel free to create an [issue](../../issues) on GitHub, we'll try to address it as soon as possible.
124+
125+
If you've found a bug regarding security please mail [info@javaabu.com](mailto:info@javaabu.com) instead of using the issue tracker.
126+
127+
## Testing
128+
129+
```bash
130+
pip install -e ".[test]"
131+
pytest
132+
```
133+
134+
## Changelog
135+
136+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
137+
138+
## Contributing
139+
140+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
141+
142+
## Security
143+
144+
If you discover any security related issues, please email [info@javaabu.com](mailto:info@javaabu.com) instead of using the issue tracker.
145+
146+
## Credits
147+
148+
- [Javaabu Pvt. Ltd.](https://github.com/javaabu)
149+
- [All Contributors](../../contributors)
150+
151+
## License
152+
153+
The MIT License (MIT). Please see [License File](LICENSE) for more information.

0 commit comments

Comments
 (0)