Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
005bd26
Follow quick start guide
juliannguyen4 Apr 26, 2026
a7ac117
Prevent silent failing
juliannguyen4 Apr 26, 2026
b9676ba
Add doctest to test code examples in aerospike module rst docs. TODO …
juliannguyen4 Apr 26, 2026
9410da7
Try running with doc/*.rst to see what files get inspected
juliannguyen4 Apr 26, 2026
054b8a1
*.rst doesn't show any output. Try checking a specific file
juliannguyen4 Apr 26, 2026
7e1e1e6
need verbose mode to see number of tests run and whether they passed
juliannguyen4 Apr 26, 2026
2b0446c
Update code example to be doctest compatible. TODO - see how it appea…
juliannguyen4 Apr 26, 2026
aeee4d6
Move doctest to smoke tests to use python client build in order to im…
juliannguyen4 Apr 26, 2026
cb8f30f
Reuse job that deploys server to run doctest examples
juliannguyen4 Apr 26, 2026
ee30366
Move doctest to CE test to avoid needing to login as user
juliannguyen4 Apr 26, 2026
5bede57
Do this to avoid running doc test on every python version
juliannguyen4 Apr 26, 2026
2fd1829
fix workflow
juliannguyen4 Apr 26, 2026
c8fe007
Add sphinx_copybutton extension to make copying doctest-formatted cod…
juliannguyen4 Apr 26, 2026
865ceae
Follow 'use and customize' guide for sphinx-copybutton to skip copyin…
juliannguyen4 Apr 26, 2026
17aa74c
Add back comments
juliannguyen4 Apr 26, 2026
a15032a
Convert all code examples to be doctest compatible TODO - except for …
juliannguyen4 Apr 26, 2026
50664bc
Fix doctest formatting. Not sure why sphinx didn't fail bc of this
juliannguyen4 Apr 26, 2026
9ba17f0
Fix reported failures. Exception detail doesn't matter since it's a t…
juliannguyen4 Apr 27, 2026
14d5820
Add custom script to run all doctest code examples. This allows us to…
juliannguyen4 Apr 27, 2026
667460f
Mv script name to prevent shadowing doctest package
juliannguyen4 Apr 27, 2026
86b1f35
Fix workflow
juliannguyen4 Apr 27, 2026
1758e56
Try using this method instead to run the boilerplate code before ever…
juliannguyen4 Apr 27, 2026
f7664a2
Use doctest builder to run doctest in client.rst
juliannguyen4 Apr 27, 2026
0b3af6d
Forgot that pinned sphinx version requires 3.12 or higher
juliannguyen4 Apr 27, 2026
bebf000
Fix syntax
juliannguyen4 Apr 27, 2026
a59305f
Noticed some aerospike.* methods in aerospike.rst are returning Magic…
juliannguyen4 Apr 27, 2026
52418be
Fix HyperLogLog code example
juliannguyen4 Apr 27, 2026
d04848c
Fix formatting. Output here is correct
juliannguyen4 Apr 27, 2026
2d047be
Try testcode block, if it works then just move the other code example…
juliannguyen4 Apr 27, 2026
efb9f78
Fix hyperloglog..
juliannguyen4 Apr 27, 2026
153cfa7
Think it's safe to remove code to run doctest if we are already using…
juliannguyen4 Apr 27, 2026
5223348
Fix prepend code example
juliannguyen4 Apr 27, 2026
71c6941
Make most of the code examples in client.rst testable.
juliannguyen4 Apr 27, 2026
03fbd13
Test if this command works in aerospike_helpers
juliannguyen4 Apr 27, 2026
6e86937
Try this setting in order to build docs for aerospike_helpers.
juliannguyen4 Apr 27, 2026
7cb953d
Add back example label.
juliannguyen4 Apr 27, 2026
8ddf498
Replace 'Example::' with testcode directive for sphinx doctest to check
juliannguyen4 Apr 27, 2026
66dcce0
Revert code examples back to code-output-style blocks since sphinx do…
juliannguyen4 Apr 28, 2026
0620de5
Rm unused script now that we use sphinx doctest
juliannguyen4 Apr 28, 2026
ad7b685
Fix code example outputs causing doc build to fail
juliannguyen4 Apr 28, 2026
6e83983
Add testsetup block to fix many errors in aerospike_helpers.expressio…
juliannguyen4 Apr 28, 2026
72615a1
Fix a few bad/inconsistent code examples
juliannguyen4 Apr 28, 2026
f966c32
Fix more bad code examples..
juliannguyen4 Apr 28, 2026
16d0bbb
Improve naming for one code example. Fix another example
juliannguyen4 Apr 28, 2026
ef4ef1f
Add missing import
juliannguyen4 Apr 28, 2026
817450d
Add debug print to see why operation code is not an integer
juliannguyen4 Apr 29, 2026
d260ec0
Debug further
juliannguyen4 Apr 29, 2026
cf83d66
Add debug prints in glue code to see what type the client sees. TODO …
juliannguyen4 Apr 29, 2026
a222bd8
fix compiler error
juliannguyen4 Apr 29, 2026
65eb2d5
Make compatible with Python 3.10. PyType_GetName isn't available in t…
juliannguyen4 Apr 29, 2026
94f1a16
Use better method
juliannguyen4 Apr 29, 2026
e184e70
Printed out the type of the module constant, but try seeing what is a…
juliannguyen4 Apr 30, 2026
26e0cf3
Forgot to print to stderr. doctest captures stdout
juliannguyen4 Apr 30, 2026
21e30b6
Try not mocking out aerospike to see if doctest extension depends on …
juliannguyen4 Apr 30, 2026
d319647
Conditionally mock out aerospike if it isn't installed. This way doct…
juliannguyen4 Apr 30, 2026
792b1b6
Fix 2 code examples in aerospike.rst. This assumes the elements are r…
juliannguyen4 Apr 30, 2026
f4e3b84
Expand code example for hyperloglog
juliannguyen4 Apr 30, 2026
dca10b0
Address a few more code examples failing.
juliannguyen4 Apr 30, 2026
46b4a20
Address more code example failures. Use ellipsis for nonexact matches
juliannguyen4 Apr 30, 2026
2477217
Fix udf examples
juliannguyen4 Apr 30, 2026
5bb7d3f
Add missing import
juliannguyen4 Apr 30, 2026
3145ba7
Make sure udf output matches code example
juliannguyen4 Apr 30, 2026
fa2a5f6
Fix indentation
juliannguyen4 Apr 30, 2026
45f8580
Add missing key
juliannguyen4 Apr 30, 2026
e5b0d3a
Attempt to fix udf code example error
juliannguyen4 Apr 30, 2026
ef1a6b1
This example doesn't explicitly test ttl/gen so we can just ignore it
juliannguyen4 Apr 30, 2026
3a0a1ae
Address one test failure
juliannguyen4 Apr 30, 2026
5ec69d2
Address a few errors
juliannguyen4 May 1, 2026
8d9675a
Address a few errors
juliannguyen4 May 1, 2026
6d295c9
Getting import errors for expr op examples. Not sure why this is happ…
juliannguyen4 May 1, 2026
23e1d2a
Show logs to see why HyperLogLog code example fails
juliannguyen4 May 1, 2026
e36bc42
Add scaffolding for hll code examples TODO not done
juliannguyen4 May 1, 2026
047f82e
Fix code example by creating hll object in server instead of in code …
juliannguyen4 May 8, 2026
86daa85
Fix indenting
juliannguyen4 May 8, 2026
4676596
Address failing test case
juliannguyen4 May 8, 2026
0e11e73
Address failing test case
juliannguyen4 May 8, 2026
ae9e462
Fix bad syntax in example
juliannguyen4 May 8, 2026
7966d2c
Just noticed this is a duplicate code example for the same class
juliannguyen4 May 8, 2026
f767326
Revise one code example to make more clear how this works
juliannguyen4 May 8, 2026
cbe173e
Fix syntax error
juliannguyen4 May 8, 2026
2d6178d
Merge remote-tracking branch 'origin/dev' into CLIENT-4702-doc-valida…
juliannguyen4 May 15, 2026
25821d1
Convert remaining python code examples
juliannguyen4 May 15, 2026
58fb349
Address doctest failure by checking dict in the order the keys are re…
juliannguyen4 May 15, 2026
7d6ad8e
Address indent error in code examples
juliannguyen4 May 15, 2026
e4d0a55
Address doctest failure
juliannguyen4 May 15, 2026
d1effb9
Fix formatting
juliannguyen4 May 15, 2026
e3ab81c
Address doctest failures
juliannguyen4 May 15, 2026
552305f
Address test failure. Assuming doctest only returns strs as single qu…
juliannguyen4 May 15, 2026
570c771
Addr test failures
juliannguyen4 May 15, 2026
7022991
Add missing import
juliannguyen4 May 15, 2026
50103a3
Fill in missing boilerplate code for HLL examples.
juliannguyen4 May 15, 2026
dcb6f45
testsetup block has key defined. Make sure it runs
juliannguyen4 May 15, 2026
9e348a1
Revert code changes used for debugging failing doctest errors.
juliannguyen4 May 15, 2026
8c7b550
Since testblock is hidden and there's no option to show it, have a du…
juliannguyen4 May 15, 2026
a758b7c
Rm dup import.
juliannguyen4 May 15, 2026
f0d72c1
Merge remote-tracking branch 'origin/dev' into CLIENT-4702-doc-valida…
juliannguyen4 Jun 3, 2026
653bd20
Merge remote-tracking branch 'origin/dev' into CLIENT-4702-doc-valida…
juliannguyen4 Jun 3, 2026
e9452d1
Use minimum supported python version for current sphinx version
juliannguyen4 Jun 3, 2026
2688b0b
Prevent either a failing stubtest or doctest run from affecting each …
juliannguyen4 Jun 3, 2026
2e9dcfd
Use env var to determine python version to pull wheel and install python
juliannguyen4 Jun 3, 2026
54de454
Address regression where doctest doesn't have a server to run against
juliannguyen4 Jun 3, 2026
37a28c6
Address doctest failures
juliannguyen4 Jun 3, 2026
bead2a7
Make HLLAdd code example more meaningful
juliannguyen4 Jun 3, 2026
a468903
Provide more helpful output for HLLDescribe code example
juliannguyen4 Jun 3, 2026
40d752f
Address doctest failures by fixing the testcode syntax.
juliannguyen4 Jun 3, 2026
9703b25
Use f-strings and a separate python script to reduce code duplication
juliannguyen4 Jun 3, 2026
7fbc682
Fix python syntax
juliannguyen4 Jun 3, 2026
44ab356
Add missing boilerplate script
juliannguyen4 Jun 3, 2026
3eae364
Rerun doctest if the boilerplate testsetup code changes
juliannguyen4 Jun 3, 2026
e46eae2
Fix smoke tests not triggering.
juliannguyen4 Jun 3, 2026
7104128
Revert "Add missing boilerplate script"
juliannguyen4 Jun 3, 2026
7f0c5a8
Revert "Fix smoke tests not triggering."
juliannguyen4 Jun 3, 2026
7b153cb
Revert "Rerun doctest if the boilerplate testsetup code changes"
juliannguyen4 Jun 3, 2026
82eba7d
Always run doctest when docs/ has changes.
juliannguyen4 Jun 3, 2026
c3bd949
Add back duplicated python setup code as a workaround for testsetup n…
juliannguyen4 Jun 3, 2026
a94d1ee
Merge remote-tracking branch 'origin/dev' into CLIENT-4702-doc-valida…
juliannguyen4 Jun 3, 2026
621ecaf
Lock setup-aerospike-server for doctest.
juliannguyen4 Jun 3, 2026
431ca2d
Dont think these comments matter anymore if the code example for clie…
juliannguyen4 Jun 3, 2026
e3cd0fa
Remove old mock logic now that autodoc_mock_imports is used.
juliannguyen4 Jun 3, 2026
fb0850f
Elaborate the format of client.info_all()'s output since the tested c…
juliannguyen4 Jun 3, 2026
d4999e6
Use testcode block instead of doctest. Doesn't make sense to print ou…
juliannguyen4 Jun 4, 2026
fab78ed
Address remaining codeblocks that weren't tested. Not testing scan.rs…
juliannguyen4 Jun 4, 2026
2c4b585
Fix code example. Address inconsistent indenting
juliannguyen4 Jun 4, 2026
5e81027
Ignore these code examples since they don't work independently
juliannguyen4 Jun 4, 2026
e051e8e
Add missing boilerplate. I think this code example is worth keeping s…
juliannguyen4 Jun 4, 2026
4d5dde1
Merge remote-tracking branch 'origin/dev' into CLIENT-4702-doc-valida…
juliannguyen4 Jun 5, 2026
bf0cb4c
Manually move some of the code examples in client.rst to testcode dir…
juliannguyen4 Jun 5, 2026
e6564b9
Move all code examples from doc/examples to testcode blocks for sphin…
juliannguyen4 Jun 5, 2026
a550a6e
Fix testcode naming
juliannguyen4 Jun 5, 2026
b00e204
Merge remote-tracking branch 'origin/dev' into CLIENT-4702-doc-valida…
juliannguyen4 Jun 18, 2026
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
118 changes: 114 additions & 4 deletions doc/aerospike.rst
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,84 @@ The following example shows the three modes of serialization:
2. Class-level user functions
3. Instance-level user functions

.. include:: examples/serializer.py
:code: python
.. testcode::

import aerospike
import marshal
import json

# Serializers and deserializers
# Both local and global serializers use json library
# Functions print which one is being used

def classSerializer(obj):
print("Using class serializer")
return json.dumps(obj)

def classDeserializer(bytes):
print("Using class deserializer")
return json.loads(bytes)

def localSerializer(obj):
print("Using local serializer")
return json.dumps(obj)

def localDeserializer(bytes):
print("Using local deserializer")
return json.loads(bytes)

# First client has class-level serializer set in aerospike module
aerospike.set_serializer(classSerializer)
aerospike.set_deserializer(classDeserializer)
config = {
'hosts': [('127.0.0.1', 3000)]
}
client = aerospike.client(config)

# Second client has instance-level serializer set in client config
config['serialization'] = (localSerializer, localDeserializer)
client2 = aerospike.client(config)

# Keys: foo1, foo2, foo3
keys = [('test', 'demo', f'foo{i}') for i in range(1, 4)]
# Tuple is an unsupported type
tupleBin = {'bin': (1, 2, 3)}

# Use the default, built-in serialization (cPickle)
client.put(keys[0], tupleBin)
(_, _, bins) = client.get(keys[0])
print(bins)

# Expected output:
# {'bin': (1, 2, 3)}

# First client uses class-level, user-defined serialization
# No instance-level serializer was declared
client.put(keys[1], tupleBin, serializer=aerospike.SERIALIZER_USER)
(_, _, bins) = client.get(keys[1])
# Notice that json-encoding a tuple produces a list
print(bins)

# Expected output:
# Using class serializer
# Using class deserializer
# {'bin': [1, 2, 3]}

# Second client uses instance-level, user-defined serialization
# Instance-level serializer overrides class-level serializer
client2.put(keys[2], tupleBin, serializer=aerospike.SERIALIZER_USER)
(_, _, bins) = client2.get(keys[2])
print(bins)

# Expected output:
# Using local serializer
# Using local deserializer
# {'bin': [1, 2, 3]}

# Cleanup
client.batch_remove(keys)
client.close()
client2.close()

Records ``foo1`` and ``foo2`` should have different encodings from each other since they use different serializers.
(record ``foo3`` uses the same encoding as ``foo2``)
Expand Down Expand Up @@ -301,8 +377,42 @@ By default:

The following example shows several different methods to configuring logging for the Aerospike Python Client:

.. include:: examples/log.py
:code: python
.. testcode::

# Enable the logging at application start, before connecting to the server.
import aerospike

## SETTING THE LOG HANDLER ##

# Clears saved log handler and disable logging
aerospike.set_log_handler(None)

# Set default log handler to print to the console
aerospike.set_log_handler()

def log_callback(level, func, path, line, msg):
print("[{}] {}".format(func, msg))

# Set log handler to custom callback function (defined above)
aerospike.set_log_handler(log_callback)


## SETTING THE LOG LEVEL ##

# disables log handling
aerospike.set_log_level(aerospike.LOG_LEVEL_OFF)

# Enables log handling and sets level to LOG_LEVEL_TRACE
aerospike.set_log_level(aerospike.LOG_LEVEL_TRACE)

# Create a client and connect it to the cluster
# This line will print use log_callback to print logs with a log level of TRACE
config = {
"hosts": [
("127.0.0.1", 3000)
]
}
client = aerospike.client(config)

.. py:function:: set_log_handler(log_handler: Optional[Callable[[int, str, str, int, str], None]])

Expand Down
60 changes: 58 additions & 2 deletions doc/aerospike_helpers.expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,64 @@ the command will filter the results.

Example:

.. include:: examples/expressions/top.py
:code: python
.. testcode::

import aerospike
from aerospike_helpers import expressions as exp
import pprint

# Connect to database
config = {"hosts": [("127.0.0.1", 3000)]}
client = aerospike.client(config)

# Write player records to database
keys = [("test", "demo", i) for i in range(1, 5)]
records = [
{'user': "Chief" , 'scores': [6, 12, 4, 21], 'kd': 1.2},
{'user': "Arbiter", 'scores': [5, 10, 5, 8] , 'kd': 1.0},
{'user': "Johnson", 'scores': [8, 17, 20, 5], 'kd': 0.9},
{'user': "Regret" , 'scores': [4, 2, 3, 5] , 'kd': 0.3}
]
for key, record in zip(keys, records):
client.put(key, record)

# Example #1: Get players with a K/D ratio >= 1.0

kdGreaterThan1 = exp.GE(exp.FloatBin("kd"), 1.0).compile()
policy = {"expressions": kdGreaterThan1}
brs = client.batch_read(keys, policy=policy)

# Pretty print records' bins
for br in brs.batch_records:
# error code for FILTERED_OUT = 27
pprint.pprint(br.record[2] if br.result != 27 else None)
# {'user': 'Chief', 'scores': [6, 12, 4, 21], 'kd': 1.2}
# {'user': 'Arbiter', 'scores': [5, 10, 5, 8], 'kd': 1.0}
# None
# None

# Example #2: Get player with scores higher than 20
# By nesting expressions, we can create complicated filters

# Get top score
getTopScore = exp.ListGetByRank(
None,
aerospike.LIST_RETURN_VALUE,
exp.ResultType.INTEGER,
-1,
exp.ListBin("scores")
)
# ...then compare it
scoreHigherThan20 = exp.GE(getTopScore, 20).compile()
policy = {"expressions": scoreHigherThan20}
brs = client.batch_read(keys, policy=policy)

for br in brs.batch_records:
pprint.pprint(br.record[2] if br.result != 27 else None)
# {'user': 'Chief', 'scores': [6, 12, 4, 21], 'kd': 1.2}
# None
# {'user': 'Johnson', 'scores': [8, 17, 20, 5], 'kd': 0.9}
# None

Currently, Aerospike expressions are supported for:
* Record commands
Expand Down
Loading
Loading