GithubHelp home page GithubHelp logo

client-py's Introduction

TiKV Client (Python)

Publish

This library is a TiKV client in Python; it supports both synchronous and asynchronous API.

It's built on top of TiKV Client in Rust via CFFI and PyO3 Python binding.

This client is still in the stage of prove-of-concept and under heavy development.

Install

This package requires Python 3.6+ and pip 19+. Currently only supports MacOS (x86_64 and aarch64) and Linux in x86_64 with GLibc >= 2.12.

pip3 install tikv-client

Install (Development)

> pip3 install maturin

> maturin build
๐Ÿน Building a mixed python/rust project
๐Ÿ”— Found pyo3 bindings
๐Ÿ Found CPython 3.8 at python3.8
๐Ÿ“ฆ Built source distribution to /home/andy/Code/client-py/target/wheels/tikv_client-0.1.0.tar.gz
    Blocking waiting for file lock on build directory
   Compiling pyo3 v0.12.3
   Compiling tikv-client v0.1.0 (/home/andy/Code/client-py)
    Finished dev [unoptimized + debuginfo] target(s) in 17.62s
๐Ÿ“ฆ Built wheel for CPython 3.8 to /home/andy/Code/client-py/target/wheels/tikv_client-0.1.0-cp38-cp38-manylinux1_x86_64.whl

> pip3 install target/wheels/tikv_client-0.1.0-cp38-cp38-manylinux1_x86_64.whl
Installing collected packages: tikv-client
Successfully installed tikv-client-0.1.0

Example

Python TiKV client is synchronous by defult:

from tikv_client import TransactionClient

client = TransactionClient.connect("127.0.0.1:2379")

txn = client.begin(pessimistic=True)
txn.put(b"k1", b"v1")
txn.put(b"k2", b"v2")
txn.put(b"k3", b"v3")
txn.put(b"k4", b"v4")
txn.put(b"k5", b"v5")
txn.commit()

snapshot = client.snapshot(client.current_timestamp())
print(snapshot.get(b"k3"))
print(snapshot.batch_get([b"k1", b"k4"]))

for k, v in snapshot.scan(b"k1", end=None, limit=10, include_start=False):
    print(k, v)

Asynchronous client is available in tikv_client.asynchronous module. Modules and classes under this modules is similar to the synchronous ones.

import asyncio
from tikv_client.asynchronous import TransactionClient

async def main():
    client = await TransactionClient.connect("127.0.0.1:2379")

    txn = await client.begin(pessimistic=True)
    await txn.put(b"k1", b"v1")
    await txn.put(b"k2", b"v2")
    await txn.put(b"k3", b"v3")
    await txn.put(b"k4", b"v4")
    await txn.put(b"k5", b"v5")
    await txn.commit()

    snapshot = client.snapshot(await client.current_timestamp())
    print(await snapshot.get(b"k3"))
    print(await snapshot.batch_get([b"k1", b"k4"]))

    for k, v in await snapshot.scan(b"k1", end=None, limit=10, include_start=False):
        print(k, v)

event_loop = asyncio.get_event_loop()
asyncio.get_event_loop().run_until_complete(main())

client-py's People

Contributors

andylokandy avatar bloodbare avatar mossaka avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.