|
1 | | -# company-python-test |
| 1 | +# Devin Python Library |
| 2 | + |
| 3 | +[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fdevalog%2Fcompany-python-test) |
| 4 | +[](https://pypi.python.org/pypi/test-package-devin) |
| 5 | + |
| 6 | +The Devin Python library provides convenient access to the Devin API from Python. |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +```sh |
| 11 | +pip install test-package-devin |
| 12 | +``` |
| 13 | + |
| 14 | +## Reference |
| 15 | + |
| 16 | +A full reference for this library is available [here](https://github.com/devalog/company-python-test/blob/HEAD/./reference.md). |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +Instantiate and use the client with the following: |
| 21 | + |
| 22 | +```python |
| 23 | +from devin import CustomClientName |
| 24 | + |
| 25 | +client = CustomClientName( |
| 26 | + base_url="https://yourhost.com/path/to/api", |
| 27 | +) |
| 28 | +client.imdb.create_movie( |
| 29 | + title="title", |
| 30 | + rating=1.1, |
| 31 | +) |
| 32 | +``` |
| 33 | + |
| 34 | +## Async Client |
| 35 | + |
| 36 | +The SDK also exports an `async` client so that you can make non-blocking calls to our API. |
| 37 | + |
| 38 | +```python |
| 39 | +import asyncio |
| 40 | + |
| 41 | +from devin import AsyncCustomClientName |
| 42 | + |
| 43 | +client = AsyncCustomClientName( |
| 44 | + base_url="https://yourhost.com/path/to/api", |
| 45 | +) |
| 46 | + |
| 47 | + |
| 48 | +async def main() -> None: |
| 49 | + await client.imdb.create_movie( |
| 50 | + title="title", |
| 51 | + rating=1.1, |
| 52 | + ) |
| 53 | + |
| 54 | + |
| 55 | +asyncio.run(main()) |
| 56 | +``` |
| 57 | + |
| 58 | +## Exception Handling |
| 59 | + |
| 60 | +When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error |
| 61 | +will be thrown. |
| 62 | + |
| 63 | +```python |
| 64 | +from devin.core.api_error import ApiError |
| 65 | + |
| 66 | +try: |
| 67 | + client.imdb.create_movie(...) |
| 68 | +except ApiError as e: |
| 69 | + print(e.status_code) |
| 70 | + print(e.body) |
| 71 | +``` |
| 72 | + |
| 73 | +## Advanced |
| 74 | + |
| 75 | +### Access Raw Response Data |
| 76 | + |
| 77 | +The SDK provides access to raw response data, including headers, through the `.with_raw_response` property. |
| 78 | +The `.with_raw_response` property returns a "raw" client that can be used to access the `.headers` and `.data` attributes. |
| 79 | + |
| 80 | +```python |
| 81 | +from devin import CustomClientName |
| 82 | + |
| 83 | +client = CustomClientName( |
| 84 | + ..., |
| 85 | +) |
| 86 | +response = client.imdb.with_raw_response.create_movie(...) |
| 87 | +print(response.headers) # access the response headers |
| 88 | +print(response.data) # access the underlying object |
| 89 | +``` |
| 90 | + |
| 91 | +### Retries |
| 92 | + |
| 93 | +The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long |
| 94 | +as the request is deemed retryable and the number of retry attempts has not grown larger than the configured |
| 95 | +retry limit (default: 2). |
| 96 | + |
| 97 | +A request is deemed retryable when any of the following HTTP status codes is returned: |
| 98 | + |
| 99 | +- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout) |
| 100 | +- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests) |
| 101 | +- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors) |
| 102 | + |
| 103 | +Use the `max_retries` request option to configure this behavior. |
| 104 | + |
| 105 | +```python |
| 106 | +client.imdb.create_movie(..., request_options={ |
| 107 | + "max_retries": 1 |
| 108 | +}) |
| 109 | +``` |
| 110 | + |
| 111 | +### Timeouts |
| 112 | + |
| 113 | +The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level. |
| 114 | + |
| 115 | +```python |
| 116 | + |
| 117 | +from devin import CustomClientName |
| 118 | + |
| 119 | +client = CustomClientName( |
| 120 | + ..., |
| 121 | + timeout=20.0, |
| 122 | +) |
| 123 | + |
| 124 | + |
| 125 | +# Override timeout for a specific method |
| 126 | +client.imdb.create_movie(..., request_options={ |
| 127 | + "timeout_in_seconds": 1 |
| 128 | +}) |
| 129 | +``` |
| 130 | + |
| 131 | +### Custom Client |
| 132 | + |
| 133 | +You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies |
| 134 | +and transports. |
| 135 | + |
| 136 | +```python |
| 137 | +import httpx |
| 138 | +from devin import CustomClientName |
| 139 | + |
| 140 | +client = CustomClientName( |
| 141 | + ..., |
| 142 | + httpx_client=httpx.Client( |
| 143 | + proxies="http://my.test.proxy.example.com", |
| 144 | + transport=httpx.HTTPTransport(local_address="0.0.0.0"), |
| 145 | + ), |
| 146 | +) |
| 147 | +``` |
| 148 | + |
| 149 | +## Contributing |
| 150 | + |
| 151 | +While we value open-source contributions to this SDK, this library is generated programmatically. |
| 152 | +Additions made directly to this library would have to be moved over to our generation code, |
| 153 | +otherwise they would be overwritten upon the next generated release. Feel free to open a PR as |
| 154 | +a proof of concept, but know that we will not be able to merge it as-is. We suggest opening |
| 155 | +an issue first to discuss with us! |
| 156 | + |
| 157 | +On the other hand, contributions to the README are always very welcome! |
0 commit comments