Skip to content

Commit 440f678

Browse files
authored
Merge pull request #1 from Hyphen/copilot/add-python-sdk-for-hyphen
[WIP] Add python SDK implementation for Hyphen
2 parents b341fb7 + 00ea299 commit 440f678

13 files changed

Lines changed: 1442 additions & 2 deletions

README.md

Lines changed: 352 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,352 @@
1-
# python-sdk
2-
Hyphen Python SDK
1+
# Hyphen Python SDK
2+
3+
The official Python SDK for [Hyphen](https://hyphen.ai) - providing feature toggles, IP geolocation, and link shortening services.
4+
5+
## Installation
6+
7+
```bash
8+
pip install hyphen
9+
```
10+
11+
For development:
12+
```bash
13+
pip install hyphen[dev]
14+
```
15+
16+
## Quick Start
17+
18+
### Environment Variables
19+
20+
You can set API credentials using environment variables:
21+
22+
```bash
23+
export HYPHEN_API_KEY="your_api_key"
24+
export HYPHEN_PUBLIC_API_KEY="your_public_api_key"
25+
export HYPHEN_APPLICATION_ID="your_application_id"
26+
export HYPHEN_ORGANIZATION_ID="your_organization_id"
27+
```
28+
29+
## Feature Toggles
30+
31+
Manage feature flags for your application.
32+
33+
* [Website](https://hyphen.ai)
34+
* [Guides](https://docs.hyphen.ai)
35+
36+
### Get a Single Toggle
37+
38+
```python
39+
from hyphen import FeatureToggle
40+
41+
toggle = FeatureToggle(
42+
application_id='your_application_id',
43+
api_key='your_api_key',
44+
)
45+
46+
value = toggle.get_toggle('hyphen-sdk-boolean')
47+
print('Toggle value:', value)
48+
```
49+
50+
### Get Multiple Toggles
51+
52+
```python
53+
from hyphen import FeatureToggle
54+
55+
toggle = FeatureToggle(
56+
application_id='your_application_id',
57+
api_key='your_api_key',
58+
)
59+
60+
toggles = toggle.get_toggles(['hyphen-sdk-boolean', 'hyphen-sdk-number', 'hyphen-sdk-string'])
61+
print('Toggles:', toggles)
62+
```
63+
64+
Toggles support multiple data types:
65+
- Boolean: `True` or `False`
66+
- Number: `42` (int or float)
67+
- String: `"Hello World!"`
68+
- JSON: `{"id": "Hello World!"}`
69+
70+
## NetInfo - IP Geolocation
71+
72+
Look up IP address geolocation information.
73+
74+
* [Website](https://hyphen.ai)
75+
* [Guides](https://docs.hyphen.ai)
76+
77+
### Get Single IP Information
78+
79+
```python
80+
from hyphen import NetInfo
81+
82+
net_info = NetInfo(api_key='your_api_key')
83+
84+
ip_info = net_info.get_ip_info('8.8.8.8')
85+
print('IP Info:', ip_info)
86+
```
87+
88+
### Get Multiple IP Information
89+
90+
```python
91+
from hyphen import NetInfo
92+
93+
net_info = NetInfo(api_key='your_api_key')
94+
95+
ips = ['8.8.8.8', '1.1.1.1']
96+
ip_infos = net_info.get_ip_infos(ips)
97+
print('IP Infos:', ip_infos)
98+
```
99+
100+
## Link - Short Code Service
101+
102+
Create and manage short URLs and QR codes.
103+
104+
* [Website](https://hyphen.ai/link)
105+
* [Guides](https://docs.hyphen.ai/docs/create-short-link)
106+
* [API Reference](https://docs.hyphen.ai/reference/post_api-organizations-organizationid-link-codes)
107+
108+
### Creating a Short Code
109+
110+
```python
111+
from hyphen import Link
112+
113+
link = Link(
114+
organization_id='your_organization_id',
115+
api_key='your_api_key',
116+
)
117+
118+
response = link.create_short_code(
119+
long_url='https://hyphen.ai',
120+
domain='test.h4n.link',
121+
options={
122+
'tags': ['sdk-test', 'unit-test'],
123+
}
124+
)
125+
print('Short Code Response:', response)
126+
```
127+
128+
### Updating a Short Code
129+
130+
```python
131+
from hyphen import Link
132+
133+
link = Link(
134+
organization_id='your_organization_id',
135+
api_key='your_api_key',
136+
)
137+
138+
response = link.update_short_code(
139+
code='code_1234567890',
140+
options={
141+
'title': 'Updated Short Code',
142+
'tags': ['sdk-test', 'unit-test'],
143+
'long_url': 'https://hyphen.ai/updated',
144+
}
145+
)
146+
print('Update Response:', response)
147+
```
148+
149+
### Getting a Short Code
150+
151+
```python
152+
from hyphen import Link
153+
154+
link = Link(
155+
organization_id='your_organization_id',
156+
api_key='your_api_key',
157+
)
158+
159+
response = link.get_short_code('code_1234567890')
160+
print('Short Code:', response)
161+
```
162+
163+
### Getting Short Codes
164+
165+
```python
166+
from hyphen import Link
167+
168+
link = Link(
169+
organization_id='your_organization_id',
170+
api_key='your_api_key',
171+
)
172+
173+
response = link.get_short_codes(
174+
title='My Short Codes',
175+
tags=['sdk-test', 'unit-test']
176+
)
177+
print('Short Codes:', response)
178+
```
179+
180+
### Getting Organization Tags
181+
182+
```python
183+
from hyphen import Link
184+
185+
link = Link(
186+
organization_id='your_organization_id',
187+
api_key='your_api_key',
188+
)
189+
190+
tags = link.get_tags()
191+
print('Tags:', tags)
192+
```
193+
194+
### Get Short Code Stats
195+
196+
```python
197+
from hyphen import Link
198+
from datetime import datetime
199+
200+
link = Link(
201+
organization_id='your_organization_id',
202+
api_key='your_api_key',
203+
)
204+
205+
stats = link.get_short_code_stats(
206+
code='code_1234567890',
207+
start_date=datetime(2023, 1, 1),
208+
end_date=datetime(2023, 12, 31)
209+
)
210+
print('Stats:', stats)
211+
```
212+
213+
### Deleting a Short Code
214+
215+
```python
216+
from hyphen import Link
217+
218+
link = Link(
219+
organization_id='your_organization_id',
220+
api_key='your_api_key',
221+
)
222+
223+
response = link.delete_short_code('code_1234567890')
224+
print('Delete Response:', response)
225+
```
226+
227+
### Creating a QR Code
228+
229+
```python
230+
from hyphen import Link, QrSize
231+
232+
link = Link(
233+
organization_id='your_organization_id',
234+
api_key='your_api_key',
235+
)
236+
237+
response = link.create_qr_code(
238+
code='code_1234567890',
239+
options={
240+
'title': 'My QR Code',
241+
'backgroundColor': '#ffffff',
242+
'color': '#000000',
243+
'size': QrSize.MEDIUM,
244+
}
245+
)
246+
print('QR Code:', response)
247+
```
248+
249+
### Get QR Code by ID
250+
251+
```python
252+
from hyphen import Link
253+
254+
link = Link(
255+
organization_id='your_organization_id',
256+
api_key='your_api_key',
257+
)
258+
259+
response = link.get_qr_code('code_1234567890', 'qr_1234567890')
260+
print('QR Code:', response)
261+
```
262+
263+
### Get QR Codes for a Short Code
264+
265+
```python
266+
from hyphen import Link
267+
268+
link = Link(
269+
organization_id='your_organization_id',
270+
api_key='your_api_key',
271+
)
272+
273+
response = link.get_qr_codes('code_1234567890')
274+
print('QR Codes:', response)
275+
```
276+
277+
### Deleting a QR Code
278+
279+
```python
280+
from hyphen import Link
281+
282+
link = Link(
283+
organization_id='your_organization_id',
284+
api_key='your_api_key',
285+
)
286+
287+
response = link.delete_qr_code('code_1234567890', 'qr_1234567890')
288+
print('Delete Response:', response)
289+
```
290+
291+
## Development
292+
293+
### Setup
294+
295+
```bash
296+
# Clone the repository
297+
git clone https://github.com/Hyphen/python-sdk.git
298+
cd python-sdk
299+
300+
# Install dependencies
301+
pip install -e ".[dev]"
302+
```
303+
304+
### Testing
305+
306+
Create a `.env` file with your test credentials:
307+
308+
```bash
309+
HYPHEN_PUBLIC_API_KEY=your_public_api_key
310+
HYPHEN_API_KEY=your_api_key
311+
HYPHEN_APPLICATION_ID=your_application_id
312+
HYPHEN_LINK_DOMAIN=your_link_domain
313+
HYPHEN_ORGANIZATION_ID=your_organization_id
314+
```
315+
316+
Run tests:
317+
318+
```bash
319+
pytest
320+
```
321+
322+
### Linting
323+
324+
```bash
325+
ruff check hyphen tests
326+
```
327+
328+
### Type Checking
329+
330+
```bash
331+
mypy hyphen
332+
```
333+
334+
## Contributing
335+
336+
We welcome contributions! Please follow these steps:
337+
338+
1. Fork the repository
339+
2. Create a new branch for your feature or bug fix
340+
3. Make your changes and commit them with clear messages:
341+
- `feat: describe the feature`
342+
- `fix: describe the bug fix`
343+
- `chore: describe maintenance task`
344+
4. Run tests and linting to ensure quality
345+
5. Push your changes to your forked repository
346+
6. Create a pull request to the main repository
347+
348+
## License
349+
350+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
351+
352+
Copyright © 2024 Hyphen, Inc. All rights reserved.

0 commit comments

Comments
 (0)