|
1 |
| -# @webdock/sdk |
| 1 | +# Webdock API Python SDK |
2 | 2 |
|
3 |
| -A type-safe wrapper for the Webdock.io API. |
| 3 | +A type-safe Python wrapper for the Webdock.io API. |
| 4 | + |
| 5 | +## Documentation |
| 6 | + |
| 7 | +Full API documentation is available at [api.webdock.io](https://api.webdock.io) |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +```bash |
| 12 | +pip install webdock |
| 13 | +``` |
| 14 | + |
| 15 | +## Quick Start |
| 16 | + |
| 17 | +Each operation returns both body and headers that you can access using the `get()` method: |
| 18 | + |
| 19 | +```python |
| 20 | +import time |
| 21 | +from webdock import webdock |
| 22 | +from requests import RequestException |
| 23 | + |
| 24 | +def main(): |
| 25 | + # Initialize client with your API token |
| 26 | + client = webdock.Webdock("your_api_token_here") |
| 27 | + |
| 28 | + try: |
| 29 | + # Create a new server |
| 30 | + server = client.servers.create( |
| 31 | + imageSlug="ubuntu-20-04-x64", |
| 32 | + locationId="pl-waw", |
| 33 | + name="test-server", |
| 34 | + profileSlug="s-1vcpu-1gb", |
| 35 | + ) |
| 36 | + |
| 37 | + # Access server data from response body |
| 38 | + aliases = server.get("body").get("aliases") |
| 39 | + print(f"Server aliases: {aliases}") |
| 40 | + |
| 41 | + # Access callback ID from headers to track provision operation state |
| 42 | + callback_id = server.get("headers").get("x_callback_id") |
| 43 | + print(f"Callback ID: {callback_id}") |
| 44 | + |
| 45 | + except RequestException as e: |
| 46 | + print(f"API request failed: {e}") |
| 47 | + |
| 48 | +if __name__ == "__main__": |
| 49 | + main() |
| 50 | +``` |
| 51 | + |
| 52 | +## Response Structure |
| 53 | + |
| 54 | +All API operations return a response object with two main components: |
| 55 | + |
| 56 | +- **`body`**: Contains the actual API response data |
| 57 | +- **`headers`**: Contains HTTP headers, including tracking information like `x_callback_id` |
| 58 | + |
| 59 | +### Example Usage |
| 60 | + |
| 61 | +```python |
| 62 | +# Get server information |
| 63 | +server_info = server.get("body") |
| 64 | +server_name = server_info.get("name") |
| 65 | +server_status = server_info.get("status") |
| 66 | + |
| 67 | +# Track operations using headers |
| 68 | +callback_id = server.get("headers").get("x_callback_id") |
| 69 | +``` |
| 70 | + |
| 71 | +## Backward Compatibility |
| 72 | + |
| 73 | +The legacy package is still available but deprecated. You can import it for existing projects: |
| 74 | + |
| 75 | +```python |
| 76 | +import time |
| 77 | +from oldwebdock.webdock import Webdock |
| 78 | +from requests import RequestException |
| 79 | + |
| 80 | +def main(): |
| 81 | + client = Webdock("your_api_token_here") |
| 82 | + |
| 83 | + try: |
| 84 | + # Create webhook (legacy syntax) |
| 85 | + webhook = client.create_hook( |
| 86 | + hookType="foo", |
| 87 | + hookValue="https://your-webhook-url.com" |
| 88 | + ) |
| 89 | + |
| 90 | + # Access response data (same pattern as new SDK) |
| 91 | + webhook_id = webhook.get("body").get("id") |
| 92 | + callback_id = webhook.get("headers").get("x_callback_id") |
| 93 | + |
| 94 | + except RequestException as e: |
| 95 | + print(f"Request failed: {e}") |
| 96 | + |
| 97 | +if __name__ == "__main__": |
| 98 | + main() |
| 99 | +``` |
| 100 | + |
| 101 | +> **⚠️ Deprecation Notice**: legacy package is now deprecated. Please migrate to the new SDK for continued support and updates. |
| 102 | +
|
| 103 | +## Features |
| 104 | + |
| 105 | +- **Type-safe**: Full type hints for better IDE support and error catching |
| 106 | +- **Easy to use**: Simple, intuitive API interface |
| 107 | +- **Error handling**: Built-in exception handling with detailed error messages |
| 108 | +- **Async support**: Non-blocking operations for better performance |
| 109 | +- **Comprehensive**: Full coverage of Webdock API endpoints |
| 110 | + |
| 111 | +## Support |
| 112 | + |
| 113 | +- [API Documentation](https://api.webdock.io) |
| 114 | +- [GitHub Issues](https://github.com/webdock-io/python-sdk/issues) |
| 115 | +- [Webdock Support](https://webdock.io/support) |
0 commit comments