How to use the pyignite.Client function in pyignite

To help you get started, we’ve selected a few pyignite examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gridgain / gridgain / modules / platforms / python / examples / binary_basics.py View on Github external
#
from collections import OrderedDict

from pyignite import Client, GenericObjectMeta
from pyignite.datatypes import *


class Person(metaclass=GenericObjectMeta, schema=OrderedDict([
    ('first_name', String),
    ('last_name', String),
    ('age', IntObject),
])):
    pass


client = Client()
client.connect('localhost', 10800)

person_cache = client.get_or_create_cache('person')

person_cache.put(
    1, Person(first_name='Ivan', last_name='Ivanov', age=33)
)

person = person_cache.get(1)
print(person.__class__.__name__)
# Person

print(person.__class__ is Person)
# True if `Person` was registered automatically (on writing)
# or manually (using `client.register_binary_type()` method).
# False otherwise
github gridgain / gridgain / modules / platforms / python / examples / scans.py View on Github external
#
# Licensed under the GridGain Community Edition License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from pyignite import Client

client = Client()
client.connect('127.0.0.1', 10800)

my_cache = client.create_cache('my cache')

my_cache.put_all({'key_{}'.format(v): v for v in range(20)})
# {
#     'key_0': 0,
#     'key_1': 1,
#     'key_2': 2,
#     ... 20 elements in total...
#     'key_18': 18,
#     'key_19': 19
# }

result = my_cache.scan()
for k, v in result:
github gridgain / gridgain / modules / platforms / python / pyignite / datatypes / complex.py View on Github external
def find_client():
        """
        A nice hack. Extracts the nearest `Client` instance from the
        call stack.
        """
        from pyignite import Client
        from pyignite.connection import Connection

        frame = None
        try:
            for rec in inspect.stack()[2:]:
                frame = rec[0]
                code = frame.f_code
                for varname in code.co_varnames:
                    suspect = frame.f_locals[varname]
                    if isinstance(suspect, Client):
                        return suspect
                    if isinstance(suspect, Connection):
                        return suspect.client
        finally:
            del frame
github gridgain / gridgain / modules / platforms / python / examples / failover.py View on Github external
# See the License for the specific language governing permissions and
# limitations under the License.
#
from pyignite import Client
from pyignite.datatypes.cache_config import CacheMode
from pyignite.datatypes.prop_codes import *
from pyignite.exceptions import SocketError


nodes = [
    ('127.0.0.1', 10800),
    ('127.0.0.1', 10801),
    ('127.0.0.1', 10802),
]

client = Client(timeout=4.0)
client.connect(nodes)
print('Connected to {}'.format(client))

my_cache = client.get_or_create_cache({
    PROP_NAME: 'my_cache',
    PROP_CACHE_MODE: CacheMode.REPLICATED,
})
my_cache.put('test_key', 0)

# abstract main loop
while True:
    try:
        # do the work
        test_value = my_cache.get('test_key')
        my_cache.put('test_key', test_value + 1)
    except (OSError, SocketError) as e:
github gridgain / gridgain / modules / platforms / python / examples / get_and_put.py View on Github external
#
# Licensed under the GridGain Community Edition License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from pyignite import Client

client = Client()
client.connect('127.0.0.1', 10800)

my_cache = client.create_cache('my cache')

my_cache.put('my key', 42)

result = my_cache.get('my key')
print(result)  # 42

result = my_cache.get('non-existent key')
print(result)  # None

result = my_cache.get_all([
    'my key',
    'non-existent key',
    'other-key',
github gridgain / gridgain / modules / platforms / python / examples / read_binary.py View on Github external
['CHN', 'Dong', False, Decimal('0.2')],
    ['CHN', 'Hui', False, Decimal('0.8')],
    ['CHN', 'Mantšu', False, Decimal('0.9')],
    ['CHN', 'Miao', False, Decimal('0.7')],
    ['CHN', 'Mongolian', False, Decimal('0.4')],
    ['CHN', 'Puyi', False, Decimal('0.2')],
    ['CHN', 'Tibetan', False, Decimal('0.4')],
    ['CHN', 'Tujia', False, Decimal('0.5')],
    ['CHN', 'Uighur', False, Decimal('0.6')],
    ['CHN', 'Yi', False, Decimal('0.6')],
    ['CHN', 'Zhuang', False, Decimal('1.4')],
]


# establish connection
client = Client()
client.connect('127.0.0.1', 10800)

# create tables
for query in [
    COUNTRY_CREATE_TABLE_QUERY,
    CITY_CREATE_TABLE_QUERY,
    LANGUAGE_CREATE_TABLE_QUERY,
]:
    client.sql(query)

# create indices
for query in [CITY_CREATE_INDEX, LANGUAGE_CREATE_INDEX]:
    client.sql(query)

# load data
for row in COUNTRY_DATA:
github gridgain / gridgain / modules / platforms / python / examples / sql.py View on Github external
['CHN', 'Dong', False, Decimal('0.2')],
    ['CHN', 'Hui', False, Decimal('0.8')],
    ['CHN', 'Mantšu', False, Decimal('0.9')],
    ['CHN', 'Miao', False, Decimal('0.7')],
    ['CHN', 'Mongolian', False, Decimal('0.4')],
    ['CHN', 'Puyi', False, Decimal('0.2')],
    ['CHN', 'Tibetan', False, Decimal('0.4')],
    ['CHN', 'Tujia', False, Decimal('0.5')],
    ['CHN', 'Uighur', False, Decimal('0.6')],
    ['CHN', 'Yi', False, Decimal('0.6')],
    ['CHN', 'Zhuang', False, Decimal('1.4')],
]


# establish connection
client = Client()
client.connect('127.0.0.1', 10800)

# create tables
for query in [
    COUNTRY_CREATE_TABLE_QUERY,
    CITY_CREATE_TABLE_QUERY,
    LANGUAGE_CREATE_TABLE_QUERY,
]:
    client.sql(query)

# create indices
for query in [CITY_CREATE_INDEX, LANGUAGE_CREATE_INDEX]:
    client.sql(query)

# load data
for row in COUNTRY_DATA:
github gridgain / gridgain / modules / platforms / python / examples / migrate_binary.py View on Github external
#     'report_date': DateObject,
#     'purpose': String,
#     'sum': DecimalObject,
#     'recipient': String,
#     'cashier_id': LongObject,
# }


class ExpenseVoucher(
    metaclass=GenericObjectMeta,
    schema=old_schema,
):
    pass


client = Client()
client.connect('127.0.0.1', 10800)

accounting = client.get_or_create_cache('accounting')

for key, value in old_data:
    accounting.put(key, ExpenseVoucher(**value))

data_classes = client.query_binary_type('ExpenseVoucher')
print(data_classes)
# {
#     -231598180: 
# }

s_id, data_class = data_classes.popitem()
schema = data_class.schema
github gridgain / gridgain / modules / platforms / python / examples / type_hints.py View on Github external
# Licensed under the GridGain Community Edition License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from pyignite import Client
from pyignite.datatypes import CharObject, ShortObject

client = Client()
client.connect('127.0.0.1', 10800)

my_cache = client.get_or_create_cache('my cache')

my_cache.put('my key', 42)
# value ‘42’ takes 9 bytes of memory as a LongObject

my_cache.put('my key', 42, value_hint=ShortObject)
# value ‘42’ takes only 3 bytes as a ShortObject

my_cache.put('a', 1)
# ‘a’ is a key of type String

my_cache.put('a', 2, key_hint=CharObject)
# another key ‘a’ of type CharObject was created
github gridgain / gridgain / modules / platforms / python / examples / create_binary.py View on Github external
#
#     https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from collections import OrderedDict

from pyignite import Client, GenericObjectMeta
from pyignite.datatypes import DoubleObject, IntObject, String
from pyignite.datatypes.prop_codes import *

client = Client()
client.connect('127.0.0.1', 10800)

student_cache = client.create_cache({
        PROP_NAME: 'SQL_PUBLIC_STUDENT',
        PROP_SQL_SCHEMA: 'PUBLIC',
        PROP_QUERY_ENTITIES: [
            {
                'table_name': 'Student'.upper(),
                'key_field_name': 'SID',
                'key_type_name': 'java.lang.Integer',
                'field_name_aliases': [],
                'query_fields': [
                    {
                        'name': 'SID',
                        'type_name': 'java.lang.Integer',
                        'is_key_field': True,