Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*.swp
*.bak
.env
.idea
__pycache__
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import cratedb

### Connecting to CrateDB

Connect to a CrateDB cluster in the cloud by providing hostname, user name and password:
Connect to a CrateDB Cloud cluster using SSL, by providing hostname, username, and password:

```python
crate = cratedb.CrateDB(
Expand All @@ -58,7 +58,9 @@ crate = cratedb.CrateDB(

The driver uses SSL by default.

If you're running CrateDB locally (with Docker for example), connect like this:
If you're running CrateDB on your workstation (with Docker for example,
by using `docker run --rm -it --publish=4200:4200 crate`), connect like
this:

```python
crate = cratedb.CrateDB(
Expand Down Expand Up @@ -389,7 +391,7 @@ The driver can throw the following types of exception:
Here's an example showing how to catch a network error:

```python
crate = cratedb.CrateDB("nonexist", use_ssl = False)
crate = cratedb.CrateDB("nonexist", use_ssl=False)

try:
response = crate.execute(
Expand Down Expand Up @@ -440,6 +442,7 @@ Constants for each value of `code` are provided. For example `4043` is `CRATEDB
## Examples

The [`examples`](examples/) folder contains example MicroPython scripts, some of which are for specific microcontroller boards, including the popular Raspberry Pi Pico W.
Hardware-independent example programs also work well on CPython, see [Running on CPython](./docs/cpython.md).

## Testing

Expand Down
38 changes: 38 additions & 0 deletions docs/cpython.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Running on CPython

The module is designed for [MicroPython], but also works on [CPython].

## Setup

Install Python package and project manager [uv].
```shell
{apt,brew,pip,zypper} install uv
```

Create virtualenv, and install requirements.
```shell
uv venv
uv pip install requests
```

## Usage

Start CrateDB.
```shell
docker run --rm -it --name=cratedb \
--publish=4200:4200 --publish=5432:5432 \
--env=CRATE_HEAP_SIZE=2g crate:latest -Cdiscovery.type=single-node
```
Comment on lines +20 to +25
Copy link
Member Author

@amotl amotl Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also add this snippet to the main README, to educate users how actually easy it is to get started in homelab-mode only?

Copy link
Member Author

@amotl amotl Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. ✅

If you're running CrateDB on your workstation (with Docker for example,
by using `docker run --rm -it --publish=4200:4200 crate`), connect like
this:


Invoke example programs.
```shell
source .venv/bin/activate
export PYTHONPATH=$(pwd)
python examples/example_usage.py
python examples/object_examples.py
```


[CPython]: https://en.wikipedia.org/wiki/Cpython
[MicroPython]: https://en.wikipedia.org/wiki/Micropython
[uv]: https://docs.astral.sh/uv/
10 changes: 6 additions & 4 deletions examples/example_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
import cratedb

# CrateDB Docker / local network, no SSL.
# crate = cratedb.CrateDB(host="hostname", use_ssl=False)
crate = cratedb.CrateDB(host="localhost", use_ssl=False)

# CrateDB Cloud.
# CrateDB Cloud, using SSL.
"""
crate = cratedb.CrateDB(
host="host",
user="user",
host="testdrive.cratedb.net",
user="username",
password="password"
)
"""

try:
# Create a table.
Expand Down
10 changes: 6 additions & 4 deletions examples/object_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
import cratedb

# CrateDB Docker / local network, no SSL.
# crate = cratedb.CrateDB(host="hostname", use_ssl=False)
crate = cratedb.CrateDB(host="localhost", use_ssl=False)

# CrateDB Cloud.
# CrateDB Cloud, using SSL.
"""
crate = cratedb.CrateDB(
host="host",
user="user",
host="testdrive.cratedb.net",
user="username",
password="password"
)
"""

try:
print("Drop any previous table.")
Expand Down
11 changes: 8 additions & 3 deletions examples/picow_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@

import cratedb

# Configure CrateDB driver.
# CrateDB Docker / local network, no SSL.
crate = cratedb.CrateDB(host="localhost", use_ssl=False)

# CrateDB Cloud, using SSL.
"""
crate = cratedb.CrateDB(
host="hostname",
user="username",
host="testdrive.cratedb.net",
user="username",
password="password"
)
"""

# Set up the WiFi and connect.
wlan = network.WLAN(network.STA_IF)
Expand Down