shebangrun 0.6.4__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,537 @@
1
+ Metadata-Version: 2.4
2
+ Name: shebangrun
3
+ Version: 0.6.4
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
+ #### Secrets Management
142
+ ```bash
143
+ # List secrets
144
+ shebang list-secrets
145
+
146
+ # Get secret value
147
+ shebang get-secret AWS_KEY
148
+
149
+ # Get in different formats
150
+ shebang get-secret AWS_KEY -f env # AWS_KEY="value"
151
+ shebang get-secret AWS_KEY -f json # {"AWS_KEY": "value"}
152
+
153
+ # Create/update secret
154
+ shebang put-secret AWS_KEY -v "AKIA..."
155
+ echo "secret-value" | shebang put-secret API_KEY -s
156
+
157
+ # Delete secret
158
+ shebang delete-secret AWS_KEY
159
+
160
+ # View audit log
161
+ shebang audit-secret AWS_KEY
162
+ ```
163
+
164
+ #### Script Sharing
165
+ ```bash
166
+ # List who has access
167
+ shebang list-shares myscript
168
+
169
+ # Share with specific users
170
+ shebang share myscript -u alice -u bob
171
+
172
+ # Enable "anyone with link" sharing
173
+ shebang share myscript -l
174
+
175
+ # Remove user access
176
+ shebang share myscript -u alice -r
177
+
178
+ # Remove link sharing
179
+ shebang share myscript -l -r
180
+
181
+ # List scripts (includes shared by default)
182
+ shebang list
183
+
184
+ # Hide shared scripts
185
+ shebang list -i
186
+ ```
187
+
188
+ #### Secret Substitution
189
+ ```bash
190
+ # Get script with secrets substituted
191
+ shebang get myscript -s
192
+
193
+ # Run script (secrets always substituted)
194
+ shebang run myscript
195
+ ```
196
+
197
+ #### AI Script Generation (Ultimate Tier)
198
+ ```bash
199
+ # Generate a script
200
+ shebang infer "script that rotates an image 90 degrees" image.jpg
201
+
202
+ # Execute immediately
203
+ shebang infer -e "backup database to S3" /data/db
204
+
205
+ # Save to file
206
+ shebang infer -O rotate.sh "rotate image 90 degrees"
207
+
208
+ # Save to shebang account
209
+ shebang infer -s -n rotate-image -v public "rotate image 90 degrees"
210
+
211
+ # Choose AI provider (bedrock, claude, openai)
212
+ shebang infer -p bedrock "create backup script"
213
+ ```
214
+
215
+ ### CLI Options
216
+
217
+ **Visibility:**
218
+ - `priv` - Private (encrypted, requires key)
219
+ - `unlist` - Unlisted (accessible via URL only, supports ACL sharing)
220
+ - `public` - Public (listed in community)
221
+
222
+ **Configuration:**
223
+ Stored in `~/.shebangrc`:
224
+ ```bash
225
+ SHEBANG_URL="https://shebang.run"
226
+ SHEBANG_USERNAME="myuser"
227
+ SHEBANG_CLIENT_ID="..."
228
+ SHEBANG_CLIENT_SECRET="..."
229
+ SHEBANG_KEY_PATH="/path/to/key.pem"
230
+ ```
231
+
232
+ ## Python Library
233
+
234
+ ### Google Colab Usage
235
+
236
+ ```python
237
+ import shebangrun as shebang
238
+ from google.colab import userdata
239
+
240
+ # Initialize from Colab secrets
241
+ shebangrc = userdata.get('shebangrc')
242
+ key = userdata.get('colabpem')
243
+ shebang.init(shebangrc)
244
+
245
+ # Run script with variables
246
+ results = shebang.run(
247
+ script="pythontest",
248
+ key=key,
249
+ eval=True,
250
+ accept=True,
251
+ vars={"C": 5}
252
+ )
253
+
254
+ # Access variables from script
255
+ print(results['A']) # Variables defined in script
256
+ ```
257
+
258
+ ### Simple Script Fetching
259
+
260
+ ```python
261
+ from shebangrun import run
262
+
263
+ # Fetch a script (returns content as string)
264
+ content = run(username="mpruitt", script="bashtest")
265
+ print(content)
266
+ ```
267
+
268
+ ### Execute Python Scripts
269
+
270
+ ```python
271
+ from shebangrun import run
272
+
273
+ # Fetch and execute with confirmation prompt
274
+ run(username="mpruitt", script="myscript", eval=True)
275
+
276
+ # Execute without confirmation (use with caution!)
277
+ run(username="mpruitt", script="myscript", eval=True, accept=True)
278
+ ```
279
+
280
+ ### Working with Versions
281
+
282
+ ```python
283
+ from shebangrun import run
284
+
285
+ # Get latest version
286
+ content = run(username="mpruitt", script="deploy", version="latest")
287
+
288
+ # Get specific version
289
+ content = run(username="mpruitt", script="deploy", version="v5")
290
+
291
+ # Get tagged version
292
+ content = run(username="mpruitt", script="deploy", version="dev")
293
+ ```
294
+
295
+ ### Private Scripts
296
+
297
+ ```python
298
+ from shebangrun import run
299
+
300
+ # Access private script with share token
301
+ content = run(
302
+ username="mpruitt",
303
+ script="private-script",
304
+ token="your-share-token-here"
305
+ )
306
+ ```
307
+
308
+ ## Full API Client
309
+
310
+ For more advanced usage, use the `ShebangClient` class:
311
+
312
+ ```python
313
+ from shebangrun import ShebangClient
314
+
315
+ # Initialize client
316
+ client = ShebangClient(url="shebang.run")
317
+
318
+ # Login
319
+ client.login(username="myuser", password="mypassword")
320
+
321
+ # Create a script
322
+ client.create_script(
323
+ name="hello",
324
+ content="#!/bin/bash\necho 'Hello World'",
325
+ description="My first script",
326
+ visibility="public"
327
+ )
328
+
329
+ # List your scripts
330
+ scripts = client.list_scripts()
331
+ for script in scripts:
332
+ print(f"{script['name']} - v{script['version']}")
333
+
334
+ # Update a script (creates new version)
335
+ client.update_script(
336
+ script_id=1,
337
+ content="#!/bin/bash\necho 'Hello World v2'",
338
+ tag="dev"
339
+ )
340
+
341
+ # Generate share token for private script
342
+ token = client.generate_share_token(script_id=1)
343
+ print(f"Share URL: https://shebang.run/myuser/myscript?token={token}")
344
+
345
+ # Get script metadata
346
+ meta = client.get_metadata(username="mpruitt", script="bashtest")
347
+
348
+ # Secrets management
349
+ client.create_secret("AWS_KEY", "AKIA...")
350
+ secrets = client.list_secrets()
351
+ value = client.get_secret("AWS_KEY")
352
+ audit = client.get_secret_audit("AWS_KEY")
353
+ client.delete_secret("AWS_KEY")
354
+
355
+ # Script sharing
356
+ client.add_script_access(script_id=1, usernames=["alice", "bob"])
357
+ access_list = client.list_script_access(script_id=1)
358
+ client.remove_script_access(script_id=1, access_id=5)
359
+ shared = client.list_shared_scripts()
360
+
361
+ # AI script generation (Ultimate tier)
362
+ result = client.generate_script("script that backs up database", args=["db_path"])
363
+ print(result['script']) # Generated script
364
+ print(result['tokens']) # Token usage
365
+
366
+ usage = client.get_ai_usage()
367
+ print(f"Used {usage['used']} of {usage['limit']} AI generations this month")
368
+
369
+ print(f"Version: {meta['version']}, Size: {meta['size']} bytes")
370
+
371
+ # Verify signature
372
+ verification = client.verify_signature(username="mpruitt", script="bashtest")
373
+ print(f"Signed: {verification['signed']}")
374
+ ```
375
+
376
+ ## Key Management
377
+
378
+ ```python
379
+ from shebangrun import ShebangClient
380
+
381
+ client = ShebangClient(url="shebang.run")
382
+ client.login(username="myuser", password="mypassword")
383
+
384
+ # Generate a new keypair
385
+ key = client.generate_key(name="my-signing-key")
386
+ print(f"Public Key: {key['public_key']}")
387
+ print(f"Private Key: {key['private_key']}") # Save this securely!
388
+
389
+ # List keys
390
+ keys = client.list_keys()
391
+ for key in keys:
392
+ print(f"{key['name']} - Created: {key['created_at']}")
393
+
394
+ # Import existing public key
395
+ client.import_key(
396
+ name="imported-key",
397
+ public_key="-----BEGIN PUBLIC KEY-----\n..."
398
+ )
399
+
400
+ # Delete a key
401
+ client.delete_key(key_id=1)
402
+ ```
403
+
404
+ ## Account Management
405
+
406
+ ```python
407
+ from shebangrun import ShebangClient
408
+
409
+ client = ShebangClient(url="shebang.run")
410
+ client.login(username="myuser", password="mypassword")
411
+
412
+ # Change password
413
+ client.change_password(
414
+ current_password="oldpass",
415
+ new_password="newpass"
416
+ )
417
+
418
+ # Export all data (GDPR)
419
+ data = client.export_data()
420
+ print(f"Exported {len(data['scripts'])} scripts")
421
+
422
+ # Delete account (permanent!)
423
+ client.delete_account()
424
+ ```
425
+
426
+ ## API Reference
427
+
428
+ ### `run()` Function
429
+
430
+ ```python
431
+ run(username, script, key=None, eval=False, accept=False,
432
+ url="shebang.run", version=None, token=None)
433
+ ```
434
+
435
+ **Parameters:**
436
+ - `username` (str, required): Script owner's username
437
+ - `script` (str, required): Script name
438
+ - `key` (str, optional): Private key for decryption (not yet implemented)
439
+ - `eval` (bool, optional): Execute the script in Python (default: False)
440
+ - `accept` (bool, optional): Skip confirmation when eval=True (default: False)
441
+ - `url` (str, optional): Base URL (default: "shebang.run")
442
+ - `version` (str, optional): Version tag (e.g., "latest", "v1", "dev")
443
+ - `token` (str, optional): Share token for private scripts
444
+
445
+ **Returns:**
446
+ - String content if `eval=False`
447
+ - Execution result if `eval=True`
448
+
449
+ ### `ShebangClient` Class
450
+
451
+ #### Authentication
452
+ - `register(username, email, password)` - Register new user
453
+ - `login(username, password)` - Login and get JWT token
454
+
455
+ #### Script Management
456
+ - `list_scripts()` - List user's scripts
457
+ - `get_script(username, script, version=None, token=None)` - Fetch script content
458
+ - `get_metadata(username, script)` - Get script metadata
459
+ - `verify_signature(username, script)` - Verify script signature
460
+ - `create_script(name, content, description="", visibility="private", keypair_id=None)` - Create script
461
+ - `update_script(script_id, content=None, description=None, visibility=None, tag=None, keypair_id=None)` - Update script
462
+ - `delete_script(script_id)` - Delete script
463
+ - `generate_share_token(script_id)` - Generate share token
464
+ - `revoke_share_token(script_id, token)` - Revoke share token
465
+
466
+ #### Key Management
467
+ - `list_keys()` - List keypairs
468
+ - `generate_key(name)` - Generate new keypair
469
+ - `import_key(name, public_key)` - Import public key
470
+ - `delete_key(key_id)` - Delete keypair
471
+
472
+ #### Account Management
473
+ - `change_password(current_password, new_password)` - Change password
474
+ - `export_data()` - Export all data (GDPR)
475
+ - `delete_account()` - Delete account
476
+
477
+ ## Security Notes
478
+
479
+ ⚠️ **Warning:** Using `eval=True` with `accept=True` will execute remote code without confirmation. Only use this with scripts you trust completely.
480
+
481
+ ✅ **Best Practices:**
482
+ - Always review scripts before executing with `eval=True`
483
+ - Use `accept=False` (default) to see the script before execution
484
+ - Store private keys securely, never commit them to version control
485
+ - Use environment variables for tokens and credentials
486
+ - Verify script signatures when available
487
+
488
+ ## Examples
489
+
490
+ ### Automation Script
491
+
492
+ ```python
493
+ #!/usr/bin/env python3
494
+ from shebangrun import run
495
+
496
+ # Fetch deployment script and execute with confirmation
497
+ run(
498
+ username="devops",
499
+ script="deploy-prod",
500
+ version="latest",
501
+ eval=True,
502
+ accept=False # Always confirm production deployments!
503
+ )
504
+ ```
505
+
506
+ ### CI/CD Integration
507
+
508
+ ```python
509
+ import os
510
+ from shebangrun import ShebangClient
511
+
512
+ client = ShebangClient()
513
+ client.login(
514
+ username=os.environ["SHEBANG_USER"],
515
+ password=os.environ["SHEBANG_PASS"]
516
+ )
517
+
518
+ # Update deployment script
519
+ client.update_script(
520
+ script_id=int(os.environ["DEPLOY_SCRIPT_ID"]),
521
+ content=open("deploy.sh").read(),
522
+ tag="latest"
523
+ )
524
+
525
+ print("Deployment script updated!")
526
+ ```
527
+
528
+ ## License
529
+
530
+ MIT
531
+
532
+ ## Links
533
+
534
+ - Website: https://shebang.run
535
+ - Documentation: https://shebang.run/docs
536
+ - GitHub: https://github.com/skibare87/shebangrun
537
+ - PyPI: https://pypi.org/project/shebangrun/