shebangrun 0.2.3__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,419 @@
1
+ Metadata-Version: 2.4
2
+ Name: shebangrun
3
+ Version: 0.2.3
4
+ Summary: Python client library for shebang.run
5
+ Author-email: "shebang.run" <hello@shebang.run>
6
+ License: MIT
7
+ Project-URL: Homepage, https://shebang.run
8
+ Project-URL: Documentation, https://shebang.run/docs
9
+ Project-URL: Repository, https://github.com/skibare87/shebangrun
10
+ Project-URL: Bug Tracker, https://github.com/skibare87/shebangrun/issues
11
+ Keywords: shebang,scripts,automation,devops
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.7
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Requires-Python: >=3.7
22
+ Description-Content-Type: text/markdown
23
+ Requires-Dist: requests>=2.25.0
24
+ Requires-Dist: cryptography>=3.4.0
25
+ Requires-Dist: pynacl>=1.4.0
26
+
27
+ # shebangrun Python Client
28
+
29
+ Python client library and CLI tool for [shebang.run](https://shebang.run) - a platform for hosting and sharing shell scripts with versioning, encryption, and signing.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install shebangrun
35
+ ```
36
+
37
+ This installs both the Python library and the `shebang` CLI tool.
38
+
39
+ ## CLI Tool
40
+
41
+ ### Quick Start
42
+
43
+ ```bash
44
+ # Login and generate API credentials
45
+ shebang login
46
+
47
+ # List your scripts
48
+ shebang list
49
+
50
+ # Get a script
51
+ shebang get myscript
52
+
53
+ # Run a script
54
+ shebang run myscript
55
+ ```
56
+
57
+ ### Commands
58
+
59
+ #### Login
60
+ ```bash
61
+ shebang login
62
+ ```
63
+ Interactive wizard that:
64
+ - Prompts for server URL, username, password
65
+ - Generates API credentials (Client ID/Secret)
66
+ - Saves to `~/.shebangrc`
67
+
68
+ #### List Scripts
69
+ ```bash
70
+ # Your scripts
71
+ shebang list
72
+
73
+ # Include community scripts
74
+ shebang list -c
75
+ ```
76
+
77
+ #### Search Scripts
78
+ ```bash
79
+ # Search your scripts
80
+ shebang search "deploy"
81
+
82
+ # Search community
83
+ shebang search -c "backup"
84
+ ```
85
+
86
+ #### Get Script
87
+ ```bash
88
+ # Download to stdout
89
+ shebang get myscript
90
+
91
+ # From another user
92
+ shebang get -u username scriptname
93
+
94
+ # Save to file
95
+ shebang get -O deploy.sh myscript
96
+
97
+ # Decrypt with private key
98
+ shebang get -k private.pem encrypted-script
99
+ ```
100
+
101
+ #### Run Script
102
+ ```bash
103
+ # Run with confirmation
104
+ shebang run myscript
105
+
106
+ # Auto-accept (no prompt)
107
+ shebang run -a myscript
108
+
109
+ # Pass arguments
110
+ shebang run myscript arg1 arg2
111
+
112
+ # Run and delete
113
+ shebang run -d myscript
114
+ ```
115
+
116
+ #### Key Management
117
+ ```bash
118
+ # List keys
119
+ shebang list-keys
120
+
121
+ # Create new keypair
122
+ shebang create-key
123
+ shebang create-key -O mykey.pem
124
+
125
+ # Delete key
126
+ shebang delete-key keyname
127
+ ```
128
+
129
+ #### Upload Script
130
+ ```bash
131
+ # Upload from file
132
+ shebang put -n myscript -v public -f script.sh
133
+
134
+ # Upload from stdin
135
+ cat script.sh | shebang put -n myscript -v public -s
136
+
137
+ # Upload private script with encryption
138
+ shebang put -n private-script -v priv -k my-key -f script.sh -d "My private script"
139
+ ```
140
+
141
+ ### CLI Options
142
+
143
+ **Visibility:**
144
+ - `priv` - Private (encrypted, requires key)
145
+ - `unlist` - Unlisted (accessible via URL only)
146
+ - `public` - Public (listed in community)
147
+
148
+ **Configuration:**
149
+ Stored in `~/.shebangrc`:
150
+ ```bash
151
+ SHEBANG_URL="https://shebang.run"
152
+ SHEBANG_USERNAME="myuser"
153
+ SHEBANG_CLIENT_ID="..."
154
+ SHEBANG_CLIENT_SECRET="..."
155
+ SHEBANG_KEY_PATH="/path/to/key.pem"
156
+ ```
157
+
158
+ ## Python Library
159
+
160
+ ## Python Library
161
+
162
+ ### Simple Script Fetching
163
+
164
+ ```python
165
+ from shebangrun import run
166
+
167
+ # Fetch a script (returns content as string)
168
+ content = run(username="mpruitt", script="bashtest")
169
+ print(content)
170
+ ```
171
+
172
+ ### Execute Python Scripts
173
+
174
+ ```python
175
+ from shebangrun import run
176
+
177
+ # Fetch and execute with confirmation prompt
178
+ run(username="mpruitt", script="myscript", eval=True)
179
+
180
+ # Execute without confirmation (use with caution!)
181
+ run(username="mpruitt", script="myscript", eval=True, accept=True)
182
+ ```
183
+
184
+ ### Working with Versions
185
+
186
+ ```python
187
+ from shebangrun import run
188
+
189
+ # Get latest version
190
+ content = run(username="mpruitt", script="deploy", version="latest")
191
+
192
+ # Get specific version
193
+ content = run(username="mpruitt", script="deploy", version="v5")
194
+
195
+ # Get tagged version
196
+ content = run(username="mpruitt", script="deploy", version="dev")
197
+ ```
198
+
199
+ ### Private Scripts
200
+
201
+ ```python
202
+ from shebangrun import run
203
+
204
+ # Access private script with share token
205
+ content = run(
206
+ username="mpruitt",
207
+ script="private-script",
208
+ token="your-share-token-here"
209
+ )
210
+ ```
211
+
212
+ ## Full API Client
213
+
214
+ For more advanced usage, use the `ShebangClient` class:
215
+
216
+ ```python
217
+ from shebangrun import ShebangClient
218
+
219
+ # Initialize client
220
+ client = ShebangClient(url="shebang.run")
221
+
222
+ # Login
223
+ client.login(username="myuser", password="mypassword")
224
+
225
+ # Create a script
226
+ client.create_script(
227
+ name="hello",
228
+ content="#!/bin/bash\necho 'Hello World'",
229
+ description="My first script",
230
+ visibility="public"
231
+ )
232
+
233
+ # List your scripts
234
+ scripts = client.list_scripts()
235
+ for script in scripts:
236
+ print(f"{script['name']} - v{script['version']}")
237
+
238
+ # Update a script (creates new version)
239
+ client.update_script(
240
+ script_id=1,
241
+ content="#!/bin/bash\necho 'Hello World v2'",
242
+ tag="dev"
243
+ )
244
+
245
+ # Generate share token for private script
246
+ token = client.generate_share_token(script_id=1)
247
+ print(f"Share URL: https://shebang.run/myuser/myscript?token={token}")
248
+
249
+ # Get script metadata
250
+ meta = client.get_metadata(username="mpruitt", script="bashtest")
251
+ print(f"Version: {meta['version']}, Size: {meta['size']} bytes")
252
+
253
+ # Verify signature
254
+ verification = client.verify_signature(username="mpruitt", script="bashtest")
255
+ print(f"Signed: {verification['signed']}")
256
+ ```
257
+
258
+ ## Key Management
259
+
260
+ ```python
261
+ from shebangrun import ShebangClient
262
+
263
+ client = ShebangClient(url="shebang.run")
264
+ client.login(username="myuser", password="mypassword")
265
+
266
+ # Generate a new keypair
267
+ key = client.generate_key(name="my-signing-key")
268
+ print(f"Public Key: {key['public_key']}")
269
+ print(f"Private Key: {key['private_key']}") # Save this securely!
270
+
271
+ # List keys
272
+ keys = client.list_keys()
273
+ for key in keys:
274
+ print(f"{key['name']} - Created: {key['created_at']}")
275
+
276
+ # Import existing public key
277
+ client.import_key(
278
+ name="imported-key",
279
+ public_key="-----BEGIN PUBLIC KEY-----\n..."
280
+ )
281
+
282
+ # Delete a key
283
+ client.delete_key(key_id=1)
284
+ ```
285
+
286
+ ## Account Management
287
+
288
+ ```python
289
+ from shebangrun import ShebangClient
290
+
291
+ client = ShebangClient(url="shebang.run")
292
+ client.login(username="myuser", password="mypassword")
293
+
294
+ # Change password
295
+ client.change_password(
296
+ current_password="oldpass",
297
+ new_password="newpass"
298
+ )
299
+
300
+ # Export all data (GDPR)
301
+ data = client.export_data()
302
+ print(f"Exported {len(data['scripts'])} scripts")
303
+
304
+ # Delete account (permanent!)
305
+ client.delete_account()
306
+ ```
307
+
308
+ ## API Reference
309
+
310
+ ### `run()` Function
311
+
312
+ ```python
313
+ run(username, script, key=None, eval=False, accept=False,
314
+ url="shebang.run", version=None, token=None)
315
+ ```
316
+
317
+ **Parameters:**
318
+ - `username` (str, required): Script owner's username
319
+ - `script` (str, required): Script name
320
+ - `key` (str, optional): Private key for decryption (not yet implemented)
321
+ - `eval` (bool, optional): Execute the script in Python (default: False)
322
+ - `accept` (bool, optional): Skip confirmation when eval=True (default: False)
323
+ - `url` (str, optional): Base URL (default: "shebang.run")
324
+ - `version` (str, optional): Version tag (e.g., "latest", "v1", "dev")
325
+ - `token` (str, optional): Share token for private scripts
326
+
327
+ **Returns:**
328
+ - String content if `eval=False`
329
+ - Execution result if `eval=True`
330
+
331
+ ### `ShebangClient` Class
332
+
333
+ #### Authentication
334
+ - `register(username, email, password)` - Register new user
335
+ - `login(username, password)` - Login and get JWT token
336
+
337
+ #### Script Management
338
+ - `list_scripts()` - List user's scripts
339
+ - `get_script(username, script, version=None, token=None)` - Fetch script content
340
+ - `get_metadata(username, script)` - Get script metadata
341
+ - `verify_signature(username, script)` - Verify script signature
342
+ - `create_script(name, content, description="", visibility="private", keypair_id=None)` - Create script
343
+ - `update_script(script_id, content=None, description=None, visibility=None, tag=None, keypair_id=None)` - Update script
344
+ - `delete_script(script_id)` - Delete script
345
+ - `generate_share_token(script_id)` - Generate share token
346
+ - `revoke_share_token(script_id, token)` - Revoke share token
347
+
348
+ #### Key Management
349
+ - `list_keys()` - List keypairs
350
+ - `generate_key(name)` - Generate new keypair
351
+ - `import_key(name, public_key)` - Import public key
352
+ - `delete_key(key_id)` - Delete keypair
353
+
354
+ #### Account Management
355
+ - `change_password(current_password, new_password)` - Change password
356
+ - `export_data()` - Export all data (GDPR)
357
+ - `delete_account()` - Delete account
358
+
359
+ ## Security Notes
360
+
361
+ ⚠️ **Warning:** Using `eval=True` with `accept=True` will execute remote code without confirmation. Only use this with scripts you trust completely.
362
+
363
+ ✅ **Best Practices:**
364
+ - Always review scripts before executing with `eval=True`
365
+ - Use `accept=False` (default) to see the script before execution
366
+ - Store private keys securely, never commit them to version control
367
+ - Use environment variables for tokens and credentials
368
+ - Verify script signatures when available
369
+
370
+ ## Examples
371
+
372
+ ### Automation Script
373
+
374
+ ```python
375
+ #!/usr/bin/env python3
376
+ from shebangrun import run
377
+
378
+ # Fetch deployment script and execute with confirmation
379
+ run(
380
+ username="devops",
381
+ script="deploy-prod",
382
+ version="latest",
383
+ eval=True,
384
+ accept=False # Always confirm production deployments!
385
+ )
386
+ ```
387
+
388
+ ### CI/CD Integration
389
+
390
+ ```python
391
+ import os
392
+ from shebangrun import ShebangClient
393
+
394
+ client = ShebangClient()
395
+ client.login(
396
+ username=os.environ["SHEBANG_USER"],
397
+ password=os.environ["SHEBANG_PASS"]
398
+ )
399
+
400
+ # Update deployment script
401
+ client.update_script(
402
+ script_id=int(os.environ["DEPLOY_SCRIPT_ID"]),
403
+ content=open("deploy.sh").read(),
404
+ tag="latest"
405
+ )
406
+
407
+ print("Deployment script updated!")
408
+ ```
409
+
410
+ ## License
411
+
412
+ MIT
413
+
414
+ ## Links
415
+
416
+ - Website: https://shebang.run
417
+ - Documentation: https://shebang.run/docs
418
+ - GitHub: https://github.com/skibare87/shebangrun
419
+ - PyPI: https://pypi.org/project/shebangrun/