ClickHouse C – Talk to ClickHouse using its native binary protocol
Recorded: Oct. 12, 2026, 4:10 a.m.
| Original | Summarized |
GitHub - ClickHouse/clickhouse-c: minimalist header-only library for embedded contexts · GitHub Skip to content Navigation MenuSign inAppearance settingsPlatformAI CODE CREATIONGitHub CopilotWrite better code with AIGitHub Copilot appDirect agents from issue to mergeMCP RegistryIntegrate external toolsDEVELOPER WORKFLOWSActionsAutomate any workflowCodespacesInstant dev environmentsIssuesPlan and track workCode ReviewManage code changesCode QualityEnforce quality at mergeAPPLICATION SECURITYGitHub Advanced SecurityFind and fix vulnerabilitiesCode securitySecure your code as you buildSecret protectionStop leaks before they startEXPLOREWhy GitHubDocumentationBlogChangelogMarketplaceView all featuresSolutionsBY COMPANY SIZEEnterprisesSmall and medium teamsStartupsNonprofitsBY USE CASEApp ModernizationDevSecOpsDevOpsCI/CDView all use casesBY INDUSTRYHealthcareFinancial servicesManufacturingGovernmentView all industriesView all solutionsResourcesEXPLORE BY TOPICAISoftware DevelopmentDevOpsSecurityView all topicsEXPLORE BY TYPECustomer storiesEvents & webinarsEbooks & reportsBusiness insightsGitHub SkillsSUPPORT & SERVICESDocumentationCustomer supportCommunity forumTrust centerPartnersView all resourcesOpen SourceCOMMUNITYGitHub SponsorsFund open source developersPROGRAMSSecurity LabMaintainer CommunityGitHub StarsArchive ProgramREPOSITORIESTopicsTrendingCollectionsEnterpriseENTERPRISE SOLUTIONSEnterprise platformAI-powered developer platformAVAILABLE ADD-ONSGitHub Advanced SecurityEnterprise-grade security featuresCopilot for BusinessEnterprise-grade AI featuresPremium SupportEnterprise-grade 24/7 supportPricingSearch/Sign inSign upAppearance settings You signed in with another tab or window. Reload to refresh your session. Dismiss alert ClickHouseclickhouse-cRepository navigationCodeIssuesPull requests1 (1)ActionsSecurity and qualityInsightsMore items clickhouse-cPublicNotificationsYou must be signed in to change notification settingsFork3 (3)Star19 (19)You must be signed in to star a repositoryAboutminimalist header-only library for embedded contextsclickhouse.com/docs/integrations/cResourcesReadmeApache-2.0 licenseActivityCustom propertiesStars19 starsWatchers0 watchingForks3 forksReport repositorymainBranchesTagsGo to fileCodeOpen more actions menuLatest commit History32 Commits32 CommitsFolders and filesNameNameLast commit messageLast commit date.github/workflows.github/workflows docdoc docsdocs examplesexamples testtest toolstools .gitignore.gitignore LICENSELICENSE README.mdREADME.md clickhouse-async.hclickhouse-async.h clickhouse-client.hclickhouse-client.h clickhouse-compression.hclickhouse-compression.h clickhouse-openssl.hclickhouse-openssl.h clickhouse-posix-io.hclickhouse-posix-io.h clickhouse.hclickhouse.h test.shtest.sh View all filesRepository files navigationREADMEApache-2.0 licenseMore itemsclickhouse-c #define CHC_PROVIDE_STDLIB_ALLOC #include <stdio.h> int main(void) { chc_alloc al = chc_alloc_stdlib(); chc_block_opts opts = {}; /* clickhouse-local: no BlockInfo, no custom serialization */ /* One persistent reader for the whole stream: chc_block_read keeps for (;;) { for (size_t r = 0; r < chc_block_n_rows(block); r++) chc_block_destroy(block, &al); Without it, the server emits binary type tags & chc_block_read returns Header clickhouse.h clickhouse-client.h clickhouse-async.h clickhouse-compression.h clickhouse-posix-io.h clickhouse-openssl.h Each follow-up header is independent; pick what your build needs. HTTP protocol — wrap libcurl directly. Aboutminimalist header-only library for embedded contextsclickhouse.com/docs/integrations/cResourcesReadmeApache-2.0 licenseActivityCustom propertiesStars19 starsWatchers0 watchingForks3 forksReport repositoryUsed byContributorsLanguages Footer © 2026 GitHub, Inc. Footer navigation Terms Privacy Security Status Community Docs Contact Manage cookies Do not share my personal information You can’t perform that action at this time. |
The clickhouse-c library is presented as a minimalist, header-only C client designed for embedding into other contexts, such as PostgreSQL extensions, while handling communication with the ClickHouse Native wire format over TCP. The library is structured around a core set of headers, where functionality is partitioned, allowing consumers to select only the necessary components, which supports a modular design through specialized follow-up headers. The fundamental architecture relies on a separation of declarations and implementation. The library distributes its code such that each header contains both the necessary declarations and the implementation, guarded by a sentinel macro. Only one translation unit defines the implementation macro and includes the necessary headers, while other translation units include only the declarations, enforcing a clean separation between interface and concrete code. A utility macro, CHC_PROVIDE_STDLIB_ALLOC, is used to provide standard library memory allocation routines behind the declarations. The core functionality is encapsulated within headers such as clickhouse.h, which provides essential types, error handling, allocation routines, input/output mechanisms, and the block reading and writing logic. Further specialization is achieved through modular headers addressing specific transport and protocol details. clickhouse-client.h manages the higher-level TCP packet loop, handling messages like Hello, Queries, Data transfers, and error conditions. For handling data formats, clickhouse-compression.h deals with the structure of compressed frames, including support for codecs like LZ4 and ZSTD, controlled via flags like CHC_NO_LZ4. Input/Output operations are managed by distinct modules. clickhouse-posix-io.h implements the I/O layer using blocking read and write system calls, incorporating logic for handling interrupts and cancellation hooks via an EINTR loop. For environments requiring secure communication, clickhouse-openssl.h provides the necessary layer to interface with SSL/TLS streams. An alternative approach is provided by clickhouse-async.h, which implements an ioless client. This version drives the packet processing based on byte submission from the caller rather than direct socket I/O, allowing integration into event loops where the caller manages the underlying I/O mechanism such as epoll or io_uring. The design explicitly avoids implementing higher-level networking concerns like DNS, connection pooling, retry logic, or full SSL/TLS context lifecycle within the library itself, instead relying on the caller to manage these external complexities. The library offers a practical workflow for usage through a set of tests defined in test.sh, which allows verification against local servers or specialized capture tools. This testing infrastructure is designed to verify the correctness of individual components, such as block decoding, client interaction, and protocol handling, by spawning necessary server environments or proxies. The design emphasizes that complexity related to asynchronous I/O or full security context management is purposefully excluded, focusing instead on providing a low-level, format-focused block decoder usable in embedded systems. |