|
1 | | -# "Create, Read, Update, Delete"s |
| 1 | +# CRUDs |
2 | 2 |
|
3 | 3 | [](https://pypi.org/project/cruds/) |
4 | 4 | [](https://pypi.org/project/cruds/) |
5 | 5 | [](https://github.com/johnbrandborg/cruds/actions/workflows/development.yml) |
6 | 6 | [](https://sonarcloud.io/summary/new_code?id=johnbrandborg_cruds) |
7 | 7 | [](https://cruds.readthedocs.io/en/latest/?badge=latest) |
8 | 8 |
|
9 | | -**CRUDs** is a high level client library for APIs written in Python, and is ideal for back-end |
10 | | -communication, automated data processing and interactive environments like Notebooks. |
| 9 | +**CRUDs** is a lightweight Python client for REST APIs — create, read, update, |
| 10 | +and delete with zero boilerplate. |
11 | 11 |
|
12 | 12 | ```python |
13 | | ->>> import cruds |
14 | | ->>> |
15 | | ->>> catfact_ninja = cruds.Client("catfact.ninja") |
16 | | ->>> |
17 | | ->>> data = catfact_ninja.read("fact") |
18 | | ->>> type(date) # Python built-in data types you can use instantly! |
19 | | -<class 'dict'> |
20 | | -``` |
| 13 | +import cruds |
21 | 14 |
|
22 | | -## Why CRUDs? |
| 15 | +api = cruds.Client("https://api.example.com", auth="your-token") |
23 | 16 |
|
24 | | -When working with APIs, you have several options. Here's why CRUDs might be the right choice: |
| 17 | +# Create a resource |
| 18 | +user = api.create("users", data={"name": "Ada", "role": "engineer"}) |
25 | 19 |
|
26 | | -**vs. requests/httpx/urllib3:** |
27 | | -- **Semantic API Design**: Think about what you're doing (create, read, update, delete) instead of HTTP methods |
28 | | -- **Production-Ready**: Built-in retry logic, error handling, and logging without configuration |
29 | | -- **Simplified Auth**: OAuth2, bearer tokens, and basic auth handled automatically |
30 | | -- **Data-First**: Returns Python data structures directly instead of response objects |
| 20 | +# Read it back |
| 21 | +user = api.read(f"users/{user['id']}") |
31 | 22 |
|
32 | | -**vs. SDKs for specific APIs:** |
33 | | -- **Consistent Interface**: Same patterns across all APIs |
34 | | -- **No Vendor Lock-in**: Switch between APIs without learning new patterns |
35 | | -- **Lightweight**: No need for multiple heavy SDKs |
36 | | -- **Customizable**: Full control while maintaining simplicity |
| 23 | +# Update it |
| 24 | +api.update(f"users/{user['id']}", data={"role": "lead"}) |
37 | 25 |
|
38 | | -**Perfect for:** |
39 | | -- Data engineers working with multiple APIs |
40 | | -- Backend developers building integrations |
41 | | -- Data scientists in notebooks |
42 | | -- DevOps teams automating API interactions |
| 26 | +# Delete it |
| 27 | +api.delete(f"users/{user['id']}") |
| 28 | +``` |
43 | 29 |
|
44 | | -Make Create, Read, Update and Delete operations quickly, easily, and safely. CRUDs |
45 | | -aims to implement URLLib3's best practises while remaining as light as possible. |
| 30 | +No response objects to unpack. No manual JSON parsing. No boilerplate retry |
| 31 | +logic. Just your data. |
46 | 32 |
|
47 | | -Features: |
48 | | - * Authentication: Username & Password, Bearer Token and OAuth2 |
49 | | - * JSON Serialization/Deserialization |
50 | | - * Request parameters and automatically URL encoded |
51 | | - * Configurable timeouts (default 5 minutes) |
52 | | - * Exceptions handling for bad status codes |
53 | | - * Built-in retry logic with exponential backoff |
54 | | - * SSL Certificate Verification |
55 | | - * Logging for monitoring |
56 | | - * Interfaces (SDK Creation) |
| 33 | +## Quickstart |
57 | 34 |
|
58 | | -### Interfaces |
| 35 | +```bash |
| 36 | +pip install cruds |
| 37 | +``` |
59 | 38 |
|
60 | | -CRUDs provides pre-configured interfaces for popular APIs, making integration even easier: |
| 39 | +```python |
| 40 | +import cruds |
61 | 41 |
|
62 | | -* **PlanHat** - Complete customer success platform interface with 20+ data models, bulk operations, and advanced analytics. [View Documentation](https://cruds.readthedocs.io/en/latest/interfaces.html#planhat) |
| 42 | +catfacts = cruds.Client("catfact.ninja") |
| 43 | +fact = catfacts.read("fact") |
| 44 | +print(fact["fact"]) |
| 45 | +``` |
63 | 46 |
|
64 | | -### Installation |
| 47 | +## Why CRUDs over requests/httpx? |
65 | 48 |
|
66 | | -To install a stable version use [PyPI](https://pypi.org/project/cruds/). |
| 49 | +| You get | Without writing | |
| 50 | +|----------------------------|--------------------------| |
| 51 | +| Semantic CRUD methods | HTTP method boilerplate | |
| 52 | +| Automatic JSON SerDes | `.json()` / `.raise_for_status()` calls | |
| 53 | +| Retry with backoff | `HTTPAdapter` / `Retry` setup | |
| 54 | +| Bearer, Basic & OAuth2 auth| Manual header management | |
| 55 | +| SSL verification | `certifi` wiring | |
67 | 56 |
|
68 | | -```bash |
69 | | -$ pip install cruds |
| 57 | +```python |
| 58 | +# requests — 6 lines of ceremony |
| 59 | +import requests |
| 60 | +response = requests.get("https://api.example.com/users", |
| 61 | + headers={"Authorization": "Bearer token"}) |
| 62 | +response.raise_for_status() |
| 63 | +users = response.json() |
| 64 | + |
| 65 | +# CRUDs — 2 lines of intent |
| 66 | +import cruds |
| 67 | +users = cruds.Client("api.example.com", auth="token").read("users") |
70 | 68 | ``` |
71 | 69 |
|
72 | | -### Documentation |
| 70 | +## Features |
| 71 | + |
| 72 | +- **Authentication** — Bearer tokens, username/password, and OAuth2 (Client |
| 73 | + Credentials, Resource Owner Password, Authorization Code with CSRF protection) |
| 74 | +- **JSON Serialization** — Send and receive Python dicts and lists directly |
| 75 | +- **Retries with backoff** — Configurable retry count, backoff factor, and |
| 76 | + status codes (429, 500–504, etc.) |
| 77 | +- **Error handling** — Automatic exceptions for 4xx/5xx responses |
| 78 | +- **SSL verification** — Enabled by default via certifi |
| 79 | +- **Logging** — Built-in INFO/DEBUG logging for monitoring |
| 80 | +- **Interfaces** — Build SDKs with YAML configuration (ships with a full |
| 81 | + [Planhat](https://cruds.readthedocs.io/en/latest/interfaces.html#planhat) |
| 82 | + interface) |
| 83 | + |
| 84 | +## Documentation |
73 | 85 |
|
74 | | -Whether you are an data engineer wanting to retrieve or load data, a developer |
75 | | -writing software for the back-of-the-front-end, or someone wanting to contribute |
76 | | -to the project, for more information about CRUDs please visit |
77 | | -[Read the Docs](https://cruds.readthedocs.io). |
| 86 | +Full user guide, API reference, and examples at |
| 87 | +**[cruds.readthedocs.io](https://cruds.readthedocs.io)**. |
78 | 88 |
|
79 | 89 | ## License |
80 | 90 |
|
81 | | -CRUDs is released under the MIT License. See the bundled |
82 | | -[LICENSE file](https://github.com/johnbrandborg/cruds/blob/main/LICENSE) |
83 | | -for details. |
| 91 | +MIT — see [LICENSE](https://github.com/johnbrandborg/cruds/blob/main/LICENSE). |
84 | 92 |
|
85 | 93 | ## Credits |
86 | 94 |
|
87 | | -* [URLLib3 Team](https://github.com/urllib3) |
| 95 | +* [urllib3 Team](https://github.com/urllib3) |
0 commit comments