minetest-api-py/README.md

61 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

2020-05-09 14:52:04 +02:00
# MineTest Python API
This code is dirty for the moment. Experimental purpose only.
## Install
Requires MineTest `blocks` table to be on PostgreSQL.
2020-05-09 20:11:59 +02:00
Requires `python3-psycopg2` (which requires `libpq-dev`) and `cbor`:
2020-05-09 14:52:04 +02:00
sudo apt install libpq-dev
2020-05-09 20:11:59 +02:00
sudo pip3 install psycopg2 cbor
2020-05-09 14:52:04 +02:00
## Configure
Change `CONFIG_DB_CONNECT` with your PostgreSQL config string, and `CONFIG_LISTEN` with your IP and port. (leave `0.0.0.0` to listen on all addresses)
## Run
2020-06-02 15:43:01 +02:00
python3 mtapi.py
2020-05-09 14:52:04 +02:00
## Use
Beware of browsers which may replace `>` and `<` by `&lt;` and `&rt;` in url. Use commandline instead:
curl "http://127.0.0.1:8060/z=0/x>-5/x<5/y>20/y<=30"
Response is a JSON list of the blocks of which position verifies these conditions: a rectangle of 8×9×1 blocks.
{
"blocks": [
[x, y, z, data], // data is hexadecimal form of raw binary from MineTest blocks DB
...
]
}
2020-05-09 20:11:59 +02:00
Options:
* `fmt` Response format: `json` (default), `cbor`
* `cpr` Response compression: `none` (default), `gzip`, `lzma`
Example:
curl "http://127.0.0.1:8060/x>=0/x<100/y>=0/y<100/z>=0/z<100/fmt/cbor/cpr/gzip" > test_gzip.cbor
Prefer cbor+gzip for big imports. lzma is much slower than gzip but produces slightly smaller files. cbor is much smaller than json.
2020-06-02 16:24:45 +02:00
## Library
`mtdb.py` is a Python3 library for interacting with MineTest db.
import mtdb
db = mtdb.init_pgsql("host=127.0.0.1 port=5432 user=minetest password=PASSWORD dbname=minetest-world")
mtdb.get_chunk(db, (0,0,0)) # Chunk position, not node position (1 chunk = cube of 16*16*16 nodes)
2020-05-09 14:52:04 +02:00
## License
GNU AGPL 3.0
CopyLeft 2020 Pascal Engélibert