1
1
# ctrlplane-api-client
2
+
2
3
A client library for accessing Ctrlplane API
3
4
4
5
## Usage
6
+
5
7
First, create a client:
6
8
7
9
``` python
@@ -47,7 +49,7 @@ By default, when you're calling an HTTPS API it will attempt to verify that SSL
47
49
48
50
``` python
49
51
client = AuthenticatedClient(
50
- base_url = " https://internal_api.example.com" ,
52
+ base_url = " https://internal_api.example.com" ,
51
53
token = " SuperSecretToken" ,
52
54
verify_ssl = " /path/to/certificate_bundle.pem" ,
53
55
)
@@ -57,18 +59,20 @@ You can also disable certificate validation altogether, but beware that **this i
57
59
58
60
``` python
59
61
client = AuthenticatedClient(
60
- base_url = " https://internal_api.example.com" ,
61
- token = " SuperSecretToken" ,
62
+ base_url = " https://internal_api.example.com" ,
63
+ token = " SuperSecretToken" ,
62
64
verify_ssl = False
63
65
)
64
66
```
65
67
66
68
Things to know:
69
+
67
70
1 . Every path/method combo becomes a Python module with four functions:
68
- 1 . ` sync ` : Blocking request that returns parsed data (if successful) or ` None `
69
- 1 . ` sync_detailed ` : Blocking request that always returns a ` Request ` , optionally with ` parsed ` set if the request was successful.
70
- 1 . ` asyncio ` : Like ` sync ` but async instead of blocking
71
- 1 . ` asyncio_detailed ` : Like ` sync_detailed ` but async instead of blocking
71
+
72
+ 1 . ` sync ` : Blocking request that returns parsed data (if successful) or ` None `
73
+ 1 . ` sync_detailed ` : Blocking request that always returns a ` Request ` , optionally with ` parsed ` set if the request was successful.
74
+ 1 . ` asyncio ` : Like ` sync ` but async instead of blocking
75
+ 1 . ` asyncio_detailed ` : Like ` sync_detailed ` but async instead of blocking
72
76
73
77
1 . All path/query params, and bodies become method arguments.
74
78
1 . If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
@@ -110,15 +114,26 @@ client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies
110
114
```
111
115
112
116
## Building / publishing this package
113
- This project uses [ Poetry] ( https://python-poetry.org/ ) to manage dependencies and packaging. Here are the basics:
117
+
118
+ This project uses [ Poetry] ( https://python-poetry.org/ ) to manage dependencies and packaging. Here are the basics:
119
+
114
120
1 . Update the metadata in pyproject.toml (e.g. authors, version)
115
121
1 . If you're using a private repository, configure it with Poetry
116
- 1 . ` poetry config repositories.<your-repository-name> <url-to-your-repository> `
117
- 1 . ` poetry config http-basic.<your-repository-name> <username> <password> `
122
+ 1 . ` poetry config repositories.<your-repository-name> <url-to-your-repository> `
123
+ 1 . ` poetry config http-basic.<your-repository-name> <username> <password> `
118
124
1 . Publish the client with ` poetry publish --build -r <your-repository-name> ` or, if for public PyPI, just ` poetry publish --build `
119
125
120
126
If you want to install this client into another project without publishing it (e.g. for development) then:
127
+
121
128
1 . If that project ** is using Poetry** , you can simply do ` poetry add <path-to-this-client> ` from that project
122
129
1 . If that project is not using Poetry:
123
- 1 . Build a wheel with ` poetry build -f wheel `
124
- 1 . Install that wheel from the other project ` pip install <path-to-wheel> `
130
+ 1 . Build a wheel with ` poetry build -f wheel `
131
+ 1 . Install that wheel from the other project ` pip install <path-to-wheel> `
132
+
133
+ # Generate the client from the OpenAPI spec
134
+
135
+ ``` bash
136
+ openapi-python-client generate \
137
+ --output-path . \
138
+ --url https://raw.githubusercontent.com/ctrlplanedev/ctrlplane/refs/heads/main/openapi.v1.json
139
+ ```
0 commit comments