|
1 | 1 | Paperspace API for Python |
2 | 2 | ========================= |
3 | 3 |
|
4 | | -Sample usage: |
| 4 | +Sample usage |
| 5 | +============ |
| 6 | +1. Make sure you have a Paperspace account set up. Go to http://paperspace.com |
| 7 | + to register. |
| 8 | + |
| 9 | +2. Send an email message to support@paperspace.com to request access to the |
| 10 | + Paperspace API Beta program. |
| 11 | + |
| 12 | + Wait for an email confirmation indicating your account has been approved |
| 13 | + before proceeding. |
| 14 | + |
| 15 | +3. Use pip or pipenv to install the paperspace-python package: |
| 16 | + |
| 17 | + pip install paperspace |
| 18 | + |
| 19 | +4. Download your api key by executing the following: |
| 20 | + |
| 21 | + python -m paperspace.login |
| 22 | + |
| 23 | + Follow the prompts to enter your Paperspace email and password. |
| 24 | + |
| 25 | + You can also enter your credentials directly on the command line as follows: |
| 26 | + |
| 27 | + python -m paperspace.login <email> <password> [<api_token_name>] |
| 28 | + |
| 29 | + Note: your api key is cached in ~/.paperspace/config.json |
| 30 | + You can remove your cached api key by executing: |
| 31 | + |
| 32 | + python -m paperspace.logout |
| 33 | + |
| 34 | +5. Execute the sample script hello.py: |
| 35 | + |
| 36 | + python hello.py |
| 37 | + |
| 38 | + The script will be run on the remote job cluster node, and its output will be |
| 39 | + logged locally. |
| 40 | + |
| 41 | + |
| 42 | +A slightly more complex example |
| 43 | +=============================== |
| 44 | +# tests/test_remote.py |
| 45 | +import os |
| 46 | +import paperspace |
| 47 | + |
| 48 | +paperspace.jobs.runas_job({'project': 'myproject', 'machineType': 'GPU+', 'container': 'Test-Container'}) |
| 49 | + |
| 50 | +print(os.getcwd()) |
| 51 | +print('something useful') |
| 52 | + |
| 53 | + |
| 54 | +Other examples |
| 55 | +============== |
| 56 | +See the scripts in the test folder for other examples. |
| 57 | + |
| 58 | + |
| 59 | +Other Authentication options |
| 60 | +============================ |
| 61 | +1. Specify your apiKey explicitly on any of the paperspace.jobs methods, e.g.: |
| 62 | + |
| 63 | + paperspace.jobs.create({'apiKey': '1qks1hKsU7e1k...', 'project': 'myproject', 'machineType': 'GPU+', 'container': 'Test-Container'}) |
| 64 | + |
| 65 | +2. Set the package paperspace.config option in your python code: |
5 | 66 |
|
6 | | - import paperspace |
| 67 | + paperspace.config.PAPERSPACE_API_KEY = '1qks1hKsU7e1k...' |
7 | 68 |
|
8 | | - paperspace.config.PAPERSPACE_API_KEY = '14a4bc1cbc414...' |
9 | 69 |
|
10 | | - paperspace.jobs.runas_job({'project': 'myproject', 'machineType': 'GPU+', 'container': 'Test-Container'}) |
| 70 | +3. Set the PAPERSPACE_API_KEY environment variable: |
11 | 71 |
|
12 | | - print('hello paperspace!') |
| 72 | + (on linux:) export PAPERSPACE_API_KEY=1qks1hKsU7e1k... |
13 | 73 |
|
| 74 | + Note: the above methods take precedence over use of the cached api key in |
| 75 | + ~/.paperspace/config.json |
14 | 76 |
|
15 | 77 | Contributing |
16 | 78 | ============ |
|
0 commit comments