{"id":13695741,"url":"https://github.com/Infinidat/infi.clickhouse_orm","last_synced_at":"2025-05-03T13:33:09.102Z","repository":{"id":9398999,"uuid":"61994655","full_name":"Infinidat/infi.clickhouse_orm","owner":"Infinidat","description":"A Python library for working with the ClickHouse database (https://clickhouse.yandex/)","archived":false,"fork":false,"pushed_at":"2024-06-03T12:23:17.000Z","size":702,"stargazers_count":414,"open_issues_count":62,"forks_count":136,"subscribers_count":32,"default_branch":"develop","last_synced_at":"2024-11-10T19:52:45.205Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Infinidat.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-26T15:13:52.000Z","updated_at":"2024-10-31T15:56:20.000Z","dependencies_parsed_at":"2023-01-13T15:20:18.939Z","dependency_job_id":"4b25a646-95a0-4562-b739-46b4edb474b2","html_url":"https://github.com/Infinidat/infi.clickhouse_orm","commit_stats":{"total_commits":403,"total_committers":32,"mean_commits":12.59375,"dds":0.3548387096774194,"last_synced_commit":"45a9200ff6e05dd7623219c4731acc14db04bfc5"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infinidat%2Finfi.clickhouse_orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infinidat%2Finfi.clickhouse_orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infinidat%2Finfi.clickhouse_orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infinidat%2Finfi.clickhouse_orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Infinidat","download_url":"https://codeload.github.com/Infinidat/infi.clickhouse_orm/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224364367,"owners_count":17299056,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T18:00:32.985Z","updated_at":"2024-11-12T23:30:50.336Z","avatar_url":"https://github.com/Infinidat.png","language":"Python","funding_links":[],"categories":["Python","Language bindings"],"sub_categories":["Python"],"readme":"Introduction\n============\n\nThis project is simple ORM for working with the [ClickHouse database](https://clickhouse.yandex/).\nIt allows you to define model classes whose instances can be written to the database and read from it.\n\nLet's jump right in with a simple example of monitoring CPU usage. First we need to define the model class,\nconnect to the database and create a table for the model:\n\n```python\nfrom infi.clickhouse_orm import Database, Model, DateTimeField, UInt16Field, Float32Field, Memory, F\n\nclass CPUStats(Model):\n\n    timestamp = DateTimeField()\n    cpu_id = UInt16Field()\n    cpu_percent = Float32Field()\n\n    engine = Memory()\n\ndb = Database('demo')\ndb.create_table(CPUStats)\n```\n\nNow we can collect usage statistics per CPU, and write them to the database:\n\n```python\nimport psutil, time, datetime\n\npsutil.cpu_percent(percpu=True) # first sample should be discarded\nwhile True:\n    time.sleep(1)\n    stats = psutil.cpu_percent(percpu=True)\n    timestamp = datetime.datetime.now()\n    db.insert([\n        CPUStats(timestamp=timestamp, cpu_id=cpu_id, cpu_percent=cpu_percent)\n        for cpu_id, cpu_percent in enumerate(stats)\n    ])\n```\n\nQuerying the table is easy, using either the query builder or raw SQL:\n\n```python\n# Calculate what percentage of the time CPU 1 was over 95% busy\nqueryset = CPUStats.objects_in(db)\ntotal = queryset.filter(CPUStats.cpu_id == 1).count()\nbusy = queryset.filter(CPUStats.cpu_id == 1, CPUStats.cpu_percent \u003e 95).count()\nprint('CPU 1 was busy {:.2f}% of the time'.format(busy * 100.0 / total))\n\n# Calculate the average usage per CPU\nfor row in queryset.aggregate(CPUStats.cpu_id, average=F.avg(CPUStats.cpu_percent)):\n    print('CPU {row.cpu_id}: {row.average:.2f}%'.format(row=row))\n```\n\nThis and other examples can be found in the `examples` folder.\n\nTo learn more please visit the [documentation](docs/toc.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FInfinidat%2Finfi.clickhouse_orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FInfinidat%2Finfi.clickhouse_orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FInfinidat%2Finfi.clickhouse_orm/lists"}