File: README.md

package info (click to toggle)
pycfdns 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 196 kB
  • sloc: python: 233; makefile: 7
file content (162 lines) | stat: -rw-r--r-- 6,634 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Manage DNS Records hosted by Cloudflare

_[Cloudflare] DNS API Python Wrapper._

## Quick start

### Installation

```bash
python3 -m pip install pycfdns
```

### Example usage

```python
...
import aiohttp
from pycfdns import Client
...
    async with aiohttp.ClientSession() as client_session:
        client = Client(api_token="abc123", client_session=client_session)
        zones = await client.list_zones()
        print(zones)
...
```

## API

Below is a quick overview of the classes and methods that are available in this package.

This package uses [`mypy`] to ensure it is strictly typed, and all API modesl are created as [`TypedDict`] objects.

Anything that is not exported in the base of the module (in the [`__init__.py`](pycfdns/__init__.py) file) are considered internal to this package and will change wihtout any notice, yoo should consider not using anything not found there.

### Client

The [`Client` class][Client] is your entrypoint to this package, this is what's providing the methods described below.

This method accepts the folowing arguments:

Argument | Type | Description
--|--|--
`api_token` | `str` | This is your personal API token to interface with the [Cloudflare API], you can generate this token here: <https://developers.cloudflare.com/api/tokens/create>
`client_session` | `ClientSession` | This neesd to be an instance of `ClientSession` from the [`aiohttp`] pacakge.
`timeout` | `int \| None` | This determines how long an API call can use (in seconds) before it times out, the default is `10` seconds.

#### List Zones

The [`Client.list_zones` method][list_zones_method] can be used to list all zones available with the `api_token` passed to the [`Client` object][Client].

This method takes no arguments.

```python
...
client = Client(session=session, api_token="abc123")
zones = await client.list_zones()
...
```

The `zones` variable in this example will be a list of [`ZoneModel` objects][ZoneModel].

#### List Records

The [`Client.list_dns_records` method][list_dns_records_method] can be used to list all records within a zone.

This method accepts the folowing arguments:

Argument | Type | Description
--|--|--
`zone_id` | `str` | The ID of the zone to list records for.
`name` | `str \| None` | If this is passed in it will only match record matching the name.
`type` | `str \| None` | If this is passed in it will only match record matching the type.


```python
...
client = Client(api_token="abc123", client_session=client_session)
records = await client.list_dns_records()
...
```

The `records` variable in this example will be a list of [`RecordModel` objects][RecordModel].

#### Update Record

The [`Client.update_dns_record` method][update_dns_record_method] can be used to update a record in a zone.

This method accepts the folowing arguments:

Argument | Type| Description
--|--|--
`zone_id` | `str` | The ID of the zone the record exist in.
`record_id` | `str` | The ID of the record to list records for.
`record_name` | `str` | The name of the record.
`record_type` | `str` | The type of the record.
`record_content` | `str` | The content of the record.
`record_comment` | `str \| None` | The comment of the record.
`record_proxied` | `bool \| None` | The proxied state of the record.
`record_tags` | `list[str] \| None` | The tags of the record.
`record_ttl` | `int \| None` | The TTL value of the record.

```python
...
client = Client(api_token="abc123", client_session=client_session)
record = await client.update_dns_record(zone_id="abc123", record_id="abc123", record_name="abc", record_content="1.1.1.1", record_type="A")
...
```

The `record` variable in this example will be a [`RecordModel` object][RecordModel] representing the updated record.


### Exceptions

This package have 2 defined exceptions:

- [`AuthenticationException`], this will be raised when the Cloudflare API returns a status code assosiated with authentication issues.
- [`ComunicationException`], this will be raised when there are issues communicating with the [Cloudflare API].


## Versioning

This package follows the [SemVer] framework to determine how to set the version.

## Publishing

This package is published to [PyPI] when a new [GitHub] release is made.

The publishing itself is handled in [GitHub actions] with [this workflow][release_workflow].

[A history of release actions can be found here][release_history].

There is no fixed schedule for when a new version is published.


## Disclaimer

_This Python wrapper for the Cloudflare API is an independent project and is not endorsed, sponsored, or affiliated with Cloudflare, Inc. The use of Cloudflare's name, trademarks, and other intellectual property is for descriptive purposes only. All rights to Cloudflare's name, trademarks, and other intellectual property belong to Cloudflare, Inc. Use this wrapper at your own risk and ensure that you abide by Cloudflare's terms of service and API usage guidelines._

<!-- Links -->
[Cloudflare]: https://www.cloudflare.com/
[Cloudflare API]: https://developers.cloudflare.com/api/
[`mypy`]: https://www.mypy-lang.org/
[`aiohttp`]: https://docs.aiohttp.org/en/stable/
[`TypedDict`]: https://peps.python.org/pep-0589/
[SemVer]: https://semver.org/
[PyPi]: https://pypi.org/project/pycfdns/
[GitHub]: https://github.com/
[GitHub actions]: https://github.com/features/actions

[release_workflow]: https://github.com/ludeeus/pycfdns/blob/main/.github/workflows/publish.yml
[release_history]: https://github.com/ludeeus/pycfdns/actions/workflows/publish.yml

[Client]: https://github.com/search?q=repo%3Aludeeus%2Fpycfdns+symbol%3AClient+path%3Apycfdns%2Fclient.py&type=code
[list_zones_method]: https://github.com/search?q=repo%3Aludeeus%2Fpycfdns+symbol%3Alist_zones+path%3Apycfdns%2Fclient.py&type=code
[list_dns_records_method]: https://github.com/search?q=repo%3Aludeeus%2Fpycfdns+symbol%3Alist_dns_records+path%3Apycfdns%2Fclient.py&type=code
[update_dns_record_method]: https://github.com/search?q=repo%3Aludeeus%2Fpycfdns+symbol%3Aupdate_dns_record+path%3Apycfdns%2Fclient.py&type=code

[`AuthenticationException`]: https://github.com/search?q=repo%3Aludeeus%2Fpycfdns+symbol%3AAuthenticationException+path%3Apycfdns%2Fexceptions.py&type=code
[`ComunicationException`]: https://github.com/search?q=repo%3Aludeeus%2Fpycfdns+symbol%3AComunicationException+path%3Apycfdns%2Fexceptions.py&type=code

[ZoneModel]: https://github.com/search?q=repo%3Aludeeus%2Fpycfdns+symbol%3AZoneModel+path%3Apycfdns%2Fmodels.py&type=code
[RecordModel]: https://github.com/search?q=repo%3Aludeeus%2Fpycfdns+symbol%3ARecordModel+path%3Apycfdns%2Fmodels.py&type=code