gemini-on-python 0.1.1__py3-none-any.whl
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.
gemini/__init__.py
ADDED
gemini/gemini.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
|
|
3
|
+
class Gemini:
|
|
4
|
+
def __init__(self, api_key, model=None):
|
|
5
|
+
if not api_key:
|
|
6
|
+
raise ValueError("API key is required")
|
|
7
|
+
|
|
8
|
+
self.api_key = api_key
|
|
9
|
+
self.model = model or "gemini-3.5-flash-lite"
|
|
10
|
+
|
|
11
|
+
def ask(self, prompt):
|
|
12
|
+
headers = {
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
|
+
"x-goog-api-key": self.api_key
|
|
15
|
+
}
|
|
16
|
+
URL = (
|
|
17
|
+
f"https://generativelanguage.googleapis.com/v1beta/"
|
|
18
|
+
f"models/{self.model}:generateContent"
|
|
19
|
+
)
|
|
20
|
+
payload = {
|
|
21
|
+
"contents": [
|
|
22
|
+
{
|
|
23
|
+
"parts": [
|
|
24
|
+
{"text": prompt}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
response = requests.post(
|
|
30
|
+
URL,
|
|
31
|
+
headers=headers,
|
|
32
|
+
json=payload,
|
|
33
|
+
timeout=60
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
|
|
38
|
+
if response.status_code == "400":
|
|
39
|
+
raise RuntimeError(f"Gemini API request failed: Invalid API KEY")
|
|
40
|
+
|
|
41
|
+
response.raise_for_status()
|
|
42
|
+
|
|
43
|
+
data = response.json()
|
|
44
|
+
|
|
45
|
+
return data["candidates"][0]["content"]["parts"][0]["text"]
|
|
46
|
+
except requests.RequestException as error:
|
|
47
|
+
raise RuntimeError(f"Gemini API request failed: {error}") from error
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: gemini-on-python
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A lightweight Python client for the Google Gemini API
|
|
5
|
+
Project-URL: Homepage, https://github.com/phoebychubi-cyber/gemini-on-python
|
|
6
|
+
Project-URL: Repository, https://github.com/phoebychubi-cyber/gemini-on-python
|
|
7
|
+
Project-URL: Issues, https://github.com/phoebychubi-cyber/gemini-on-python/issues/
|
|
8
|
+
Author: Leaftify
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai,api,client,gemini,google,python
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# Gemini-On-Python
|
|
19
|
+
|
|
20
|
+
A lightweight Python wrapper for the Google Gemini API.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install Gemini-On-Python
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from gemini import Gemini
|
|
32
|
+
|
|
33
|
+
gemini = Gemini("your api key")
|
|
34
|
+
|
|
35
|
+
response = gemini.ask("In 1809, a British statesman was shot in the buttock during a duel with a fellow Cabinet minister, later went on to serve as Prime Minister of the United Kingdom for just 119 days in 1827 before dying in office, and—according to evolutionary biologist Stephen Jay Gould—indirectly helped set the stage for Charles Darwin's voyage on HMS Beagle. Who was this statesman?")
|
|
36
|
+
|
|
37
|
+
print(response)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
- Simple Gemini API integration
|
|
43
|
+
- Custom model selection
|
|
44
|
+
- Request timeout handling
|
|
45
|
+
- HTTP error handling
|
|
46
|
+
- Lightweight and easy to use
|
|
47
|
+
|
|
48
|
+
## Requirements
|
|
49
|
+
|
|
50
|
+
- Python 3.9+
|
|
51
|
+
- Google Gemini API key
|
|
52
|
+
|
|
53
|
+
## Configuration
|
|
54
|
+
|
|
55
|
+
You can specify a custom model:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
ai = Gemini(
|
|
59
|
+
api_key="YOUR_API_KEY",
|
|
60
|
+
model="gemini-3.5-flash-lite"
|
|
61
|
+
)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
gemini/__init__.py,sha256=lZRs-9zzhftEJxvGO4e0Udb8KyBEE3i5KzfDOuCLZWQ,48
|
|
2
|
+
gemini/gemini.py,sha256=IjlOaJ0Q2lBivPjhhvHG62vtgozpop61wiHYcguTghk,1278
|
|
3
|
+
gemini_on_python-0.1.1.dist-info/METADATA,sha256=aNleoi-btsEEBVFmpBQOkKqqzLkgFGgacBrh0QLvNoQ,1703
|
|
4
|
+
gemini_on_python-0.1.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
5
|
+
gemini_on_python-0.1.1.dist-info/licenses/LICENSE,sha256=0BSIn857Y_F3tQG9kTIsti2XlJYQLjKo3TdP9DKckjo,805
|
|
6
|
+
gemini_on_python-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Leaftify
|
|
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.
|