A fork of infi.clikchouse_orm aimed at more frequent maintenance and bugfixes.
Introduction
This project is simple ORM for working with the ClickHouse database. It allows you to define model classes whose instances can be written to the database and read from it.
Let's jump right in with a simple example of monitoring CPU usage. First we need to define the model class, connect to the database and create a table for the model:
from clickhouse_orm import Database, Model, DateTimeField, UInt16Field, Float32Field, Memory, F
class CPUStats(Model):
timestamp = DateTimeField()
cpu_id = UInt16Field()
cpu_percent = Float32Field()
engine = Memory()
db = Database('demo')
db.create_table(CPUStats)
Now we can collect usage statistics per CPU, and write them to the database:
import psutil, time, datetime
psutil.cpu_percent(percpu=True) # first sample should be discarded
while True:
time.sleep(1)
stats = psutil.cpu_percent(percpu=True)
timestamp = datetime.datetime.now()
db.insert([
CPUStats(timestamp=timestamp, cpu_id=cpu_id, cpu_percent=cpu_percent)
for cpu_id, cpu_percent in enumerate(stats)
])
Querying the table is easy, using either the query builder or raw SQL:
# Calculate what percentage of the time CPU 1 was over 95% busy
queryset = CPUStats.objects_in(db)
total = queryset.filter(CPUStats.cpu_id == 1).count()
busy = queryset.filter(CPUStats.cpu_id == 1, CPUStats.cpu_percent > 95).count()
print('CPU 1 was busy {:.2f}% of the time'.format(busy * 100.0 / total))
# Calculate the average usage per CPU
for row in queryset.aggregate(CPUStats.cpu_id, average=F.avg(CPUStats.cpu_percent)):
print('CPU {row.cpu_id}: {row.average:.2f}%'.format(row=row))
This and other examples can be found in the examples folder.
To learn more please visit the documentation.
Metadata
Release files for clickhouse-orm 4.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| clickhouse_orm-4.0.0.tar.gz | 57.2 kB | Without provenance | Details for clickhouse_orm-4.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| clickhouse_orm-4.0.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for clickhouse_orm-4.0.0-py2.py3-none-any.whl |
Total release size: 121.3 kB
Release files / clickhouse_orm-4.0.0.tar.gz
| Download URL | clickhouse_orm-4.0.0.tar.gz |
|---|---|
| Size | 57.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
417827e9406de8e49b36d7d78b9e2a331ffa3051b1eb261d5873d864cd7e5ac8
|
|
BLAKE2b-256 checksum How to use checksums |
ceb809a39ccb0155e3d7751032812569416ea2df0135b1849e10795ed8f2cea6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.16
|
Release files / clickhouse_orm-4.0.0-py2.py3-none-any.whl
| Download URL | clickhouse_orm-4.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 64.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
fdc08d77eeb085fcd3f4d15a9ec46d228062d1549705f29372804f5be88c0ffa
|
|
BLAKE2b-256 checksum How to use checksums |
65c00d2606c949917bd4cf275569b9e8a95c5ab5d54e88a7f565bbe5548cdef2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.16
|
Security for clickhouse-orm 4.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.