Skip to main content

MemSharp client for Python

A dependency-free client for MemSharp, an in-memory database for .NET that speaks RESP. Python 3.10+.

pip install ./clients/python

Start a server first: memsharp serve --port 6380.

from memsharp import MemSharpClient, WrongTypeError

with MemSharpClient(port=6380) as db:
    db.set("symbol:BTC", "68350.25")
    db.set("session:9f2", "kang", ex=1800)

    db.zadd("book:BTC:bids", {"bid-1": 68349.75})
    top = db.zrange("book:BTC:bids", 0, 9, desc=True, withscores=True)

    db.xadd("trades", {"sym": "BTC", "qty": "5"}, maxlen=100_000)
    db.ts_add("px", 68_350.25)

    # rows come back keyed by column name
    for row in db.sql("SELECT key, size FROM keys WHERE key LIKE 'order:%'"):
        print(row["key"], row["size"])

    # one round-trip for the whole batch
    db.pipeline([["SET", f"k{i}", str(i)] for i in range(1000)])

Tests

They run against a live server rather than a mock, because the only thing worth testing in a protocol client is that its bytes match what the server actually sends back.

memsharp serve --port 6391 --quiet &
python clients/python/test_client.py        # 55 checks

Notes

  • No dependencies. RESP is simple enough that a client dragging in a dependency tree costs its users more than it saves them.
  • A missing key is distinguishable from an empty one.
  • WRONGTYPE gets its own exception type, so you can catch it specifically.
  • Pipelining returns errors in place rather than raising, so one failing command does not hide the replies to the others.
  • Subscribing takes over the connection. Use a second client for ordinary commands.

Full reference, including every method: docs/en/clients.md · docs/id/clients.md

By Gravicode Studios, led by Kang Fadhil. MIT licensed.

Metadata

Release files for memsharp 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for memsharp 1.0.0
File Size Uploaded
memsharp-1.0.0.tar.gz 13.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for memsharp 1.0.0
File Interpreter ABI Platform
memsharp-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / memsharp-1.0.0.tar.gz

Download URL memsharp-1.0.0.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ffb5f8bcf02cea0fdab746ba13c180d62ba1ff994439ecb129a4893f69a42f45
BLAKE2b-256 checksum
How to use checksums
3e2d5f9cf1db22317e56acf4129b77b2f943eca23d7e84f9383a0d3c018488c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / memsharp-1.0.0-py3-none-any.whl

Download URL memsharp-1.0.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e70b284e1cdf9968b44b9f13bd4501352e0a391e9188a57e2f417b7ed5fe14e4
BLAKE2b-256 checksum
How to use checksums
91766be896ad978343715c30a639881bd24df26d59b125aa2be0aba993eec09a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page