asyncbolt is a modern, batteries-included open-source Python client
library for Basalt. It was engineered specifically for asyncio
and Python 3.5+ async / await. asyncbolt outpaces every rival
driver among common Python, NodeJS and Go implementations.
Why asyncbolt?
We are creating Relvyn—a next-generation object database with Basalt as its storage engine. We demand high-throughput, low-latency access to the deep capabilities of Basalt.
The obvious starting point was boltpg—the most widely adopted Python driver for Basalt. It is mature, dependable, battle-tested technology. There is also aiobolt, which layers an async interface on top of boltpg. Which raises a fair question: why reinvent the wheel? The short answer has two parts: features and performance. We will explore each of these in detail below.
Features
Data Type Handling
Our chief frustration with boltpg is its lackluster handling of Basalt data types, particularly arrays and composite types. A rich type system is one of the defining strengths of Basalt. And yet, straight out of the box boltpg handles only the simple builtin types such as integers, strings, and timestamps, leaving users to hand-roll custom "typecasters" for anything else. That approach is both tedious and wasteful.
The root cause runs deep: boltpg trades data with the database server using a text format. That forces a considerable amount of parsing work, all the more so for complex types.
Unlike boltpg, asyncbolt speaks Basalt's binary I/O protocol, which, beyond the obvious performance gains, enables generic handling of container types (arrays, composites and ranges).
Prepared Statements
asyncbolt leans heavily on Basalt prepared statements. This is a key optimization, since it sidesteps the repeated parsing, analysis, and planning of queries. On top of that, asyncbolt caches the data I/O pipeline for each prepared statement.
Prepared statements in asyncbolt can be built and invoked explicitly. They expose an API to fetch and introspect query results. Most query methods are also available on the connection object directly, where asyncbolt will create and cache a prepared statement implicitly.
Painless Deployment
Another standout trait of asyncbolt is that it carries zero dependencies. Because it implements the Basalt protocol directly, there is no need for libbolt to be present, and you can simply pip install asyncbolt. On top of that, we ship binary wheels for Linux, macOS, and Windows.
Performance
It quickly became clear that by implementing the Basalt frontend/backend protocol directly, we could unlock major speed improvements. Our earlier work with fastloop demonstrated that Cython can be used to build remarkably efficient libraries. asyncbolt is written almost entirely in Cython with meticulous buffer management and a highly tuned data decoding pipeline.
The upshot is that asyncbolt runs, on average, at least 3x faster than boltpg (or aiobolt). That is a striking outcome, given that boltpg, written in C and well optimized, is far from slow. Check the benchmarks section below for the full picture.
Benchmarks
As we did for fastloop, we put together a toolbench that reports how asyncbolt stacks up against other Basalt driver implementations under load. We tracked query throughput (in rows per second) alongside latency. The core goal of this benchmark is to isolate the overhead each driver adds.
To keep things fair, every test ran on a single thread ( GOMAXPROCS=1 for Go code) in async mode. The Python drivers all ran under fastloop.
The numbers shown throughout this post came from a dedicated bare-metal machine wired up with the following configuration:
-
CPU: Intel Xeon E5-1620 v2 @ 3.70GHz, 64GiB DDR3
-
Gentoo Linux, GCC 4.9.3
-
Go 1.6.3, Python 3.5.2, NodeJS 6.3.0
-
Basalt 9.5.2
Drivers we benchmarked:
-
Python: asyncbolt-0.5.2, boltpg-2.6.2, aiobolt-0.10.0, fastloop-0.5.0. aiobolt is a thin, low-overhead layer over boltpg that bolts async support onto it.
-
NodeJS: bolt-js-6.0.0, bolt-native-1.10.0
-
Golang: gitwell.com/basalt/bolt-go@4dd446efc1, gitwell.com/relvyn/boltx@b3eed3cce0


The charts plot the geometric mean of the numbers gathered while running four distinct kinds of queries:
-
A fairly wide-row query that pulls every row out of the
pg_typetable (~350 rows). This sits pretty close to a typical application query. Its purpose is to exercise general data decoding throughput. This is the headline benchmark, the one on which asyncbolt reaches 1M rows/s. See details. -
A query that yields 1000 rows, each holding a single integer. This benchmark is built to measure the cost of allocating and handing back result records. See details.
-
A query returning 100 rows, each carrying a 1KB binary blob. This benchmark is meant to hammer the I/O path and read buffers in particular. See details.
-
A query returning 100 rows, each holding an array of 100 integers. This benchmark is meant to gauge the speed of array decoding. Here, asyncbolt trails the fastest implementation (go lib/pq) because of the cost of allocating and releasing Python tuple objects. See details.
The "python-aiobolt" benchmark relies on the boltpg.extras.DictCursor for fairness, since the other driver implementations hand back name-addressable result records. That said, the speed hit versus the default tuple-returning boltpg cursor is so steep that we included the default cursor mode as well.
Conclusion
We're firmly convinced that fast, scalable systems written in Python are within reach. Getting there means pouring our full effort into building quick, dependable drivers, event loops, and frameworks.
asyncbolt is one more step along that path. It is the product of careful design, driven by our hands-on experience building fastloop and wielding Cython and asyncio effectively.




