{"id":20259942,"url":"https://github.com/influxdata/influxdb-client-swift","last_synced_at":"2025-07-15T13:12:53.043Z","repository":{"id":39972857,"uuid":"305307433","full_name":"influxdata/influxdb-client-swift","owner":"influxdata","description":"InfluxDB (v2+) Client Library for Swift","archived":false,"fork":false,"pushed_at":"2024-05-17T09:24:51.000Z","size":3416,"stargazers_count":26,"open_issues_count":4,"forks_count":9,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-06-24T23:02:17.683Z","etag":null,"topics":["flux","influxdata","influxdb","swift","swift5","timeseries"],"latest_commit_sha":null,"homepage":"https://influxdata.github.io/influxdb-client-swift/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/influxdata.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"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":"2020-10-19T08:01:37.000Z","updated_at":"2025-05-31T13:49:19.000Z","dependencies_parsed_at":"2024-05-17T10:42:04.599Z","dependency_job_id":null,"html_url":"https://github.com/influxdata/influxdb-client-swift","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/influxdata/influxdb-client-swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Finfluxdb-client-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Finfluxdb-client-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Finfluxdb-client-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Finfluxdb-client-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/influxdata","download_url":"https://codeload.github.com/influxdata/influxdb-client-swift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Finfluxdb-client-swift/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265437620,"owners_count":23765124,"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":["flux","influxdata","influxdb","swift","swift5","timeseries"],"created_at":"2024-11-14T11:17:23.875Z","updated_at":"2025-07-15T13:12:53.002Z","avatar_url":"https://github.com/influxdata.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# influxdb-client-swift\n\n[![CircleCI](https://circleci.com/gh/influxdata/influxdb-client-swift.svg?style=svg)](https://circleci.com/gh/influxdata/influxdb-client-swift)\n[![codecov](https://codecov.io/gh/influxdata/influxdb-client-swift/branch/master/graph/badge.svg)](https://codecov.io/gh/influxdata/influxdb-client-swift)\n[![Platforms](https://img.shields.io/badge/platform-macOS%20|%20iOS%20|%20watchOS%20|%20tvOS%20|%20Linux-blue.svg)](https://github.com/influxdata/influxdb-client-swift/)\n[![License](https://img.shields.io/github/license/influxdata/influxdb-client-swift.svg)](https://github.com/influxdata/influxdb-client-swift/blob/master/LICENSE)\n[![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://influxdata.github.io/influxdb-client-swift/)\n[![GitHub issues](https://img.shields.io/github/issues-raw/influxdata/influxdb-client-swift.svg)](https://github.com/influxdata/influxdb-client-swift/issues)\n[![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/influxdata/influxdb-client-swift.svg)](https://github.com/influxdata/influxdb-client-swift/pulls)\n[![Slack Status](https://img.shields.io/badge/slack-join_chat-white.svg?logo=slack\u0026style=social)](https://www.influxdata.com/slack)\n\nThis repository contains the reference Swift client for the InfluxDB 2.x.\n\n- [Features](#features)\n- [Supported Platforms](#supported-platforms)\n- [Installation](#installation)\n    - [Swift Package Manager](#swift-package-manager)\n- [Usage](#usage)\n    - [Creating a client](#creating-a-client)\n    - [Writing data](#writes)\n    - [Querying data](#queries)\n    - [Delete data](#delete-data)\n    - [Management API](#management-api)\n- [Advanced Usage](#advanced-usage)\n    - [Default Tags](#default-tags)\n    - [Proxy and redirects](#proxy-and-redirects)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Documentation\n\nThis section contains links to the client library documentation.\n\n* [Product documentation](https://docs.influxdata.com/influxdb/latest/api-guide/client-libraries/), [Getting Started](#installation)\n* [Examples](Examples/README.md#examples)\n* [API Reference](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDBClient.html)\n* [Changelog](CHANGELOG.md)\n\n## Features\n\nInfluxDB 2.x client consists of two packages\n\n- `InfluxDBSwift`\n  - Querying data using the Flux language\n  - Writing data\n    - batched in chunks on background\n    - automatic retries on write failures\n- `InfluxDBSwiftApis`\n  - provides all other InfluxDB 2.x APIs for managing\n    - health check\n    - sources, buckets\n    - tasks\n    - authorizations\n    - ...\n  - built on top of `InfluxDBSwift`\n\n## Supported Platforms\n\nThis package requires Swift 5 and Xcode 12+.\n\n- iOS 14.0+\n- macOS 11.0+\n- tvOS 14.0+\n- watchOS 7.0+\n- Linux\n\n## Installation\n\n### Swift Package Manager\n\nAdd this line to your `Package.swift` :\n\n~~~swift\n// swift-tools-version:5.3\nimport PackageDescription\n\nlet package = Package(\n    name: \"MyPackage\",\n    dependencies: [\n        .package(name: \"influxdb-client-swift\", url: \"https://github.com/influxdata/influxdb-client-swift\", from: \"1.7.0\"),\n    ],\n    targets: [\n        .target(name: \"MyModule\", dependencies: [\n          .product(name: \"InfluxDBSwift\", package: \"influxdb-client-swift\"),\n          // or InfluxDBSwiftApis for management API\n          .product(name: \"InfluxDBSwiftApis\", package: \"influxdb-client-swift\")\n        ])\n    ]\n)\n~~~\n\n## Usage\n\n\u003e Important: You should call `close()` at the end of your application to release allocated resources.\n\n### Creating a client\nSpecify **url** and **token** via parameters:\n\n```swift\nlet client = InfluxDBClient(url: \"http://localhost:8086\", token: \"my-token\")\n\n...\n\nclient.close()\n```\n\n#### Client Options\n\n| Option                     | Description                                                                   | Type               | Default |\n|----------------------------|-------------------------------------------------------------------------------|--------------------|---------|\n| bucket                     | Default destination bucket for writes                                         | String             | none    |\n| org                        | Default organization bucket for writes                                        | String             | none    |\n| precision                  | Default precision for the unix timestamps within the body line-protocol       | TimestampPrecision | ns      |\n| timeoutIntervalForRequest  | The timeout interval to use when waiting for additional data.                 | TimeInterval       | 60 sec  |\n| timeoutIntervalForResource | The maximum amount of time that a resource request should be allowed to take. | TimeInterval       | 5 min   |\n| enableGzip                 | Enable Gzip compression for HTTP requests.                                    | Bool               | false   |\n| debugging                  | Enable debugging for HTTP request/response.                                   | Bool               | false   |\n\n##### Configure default `Bucket`, `Organization` and `Precision`\n\n```swift\nlet options: InfluxDBClient.InfluxDBOptions = InfluxDBClient.InfluxDBOptions(\n        bucket: \"my-bucket\",\n        org: \"my-org\",\n        precision: .ns)\n\nlet client = InfluxDBClient(url: \"http://localhost:8086\", token: \"my-token\", options: options)\n\n...\n\nclient.close()\n```\n\n#### InfluxDB 1.8 API compatibility\n\n```swift\nclient = InfluxDBClient(\n        url: \"http://localhost:8086\", \n        username: \"user\", \n        password: \"pass\",\n        database: \"my-db\", \n        retentionPolicy: \"autogen\")\n\n...\n\nclient.close()\n```\n\n### Writes\n\nThe WriteApi supports asynchronous writes into InfluxDB 2.x. \nThe results of writes could be handled by `(response, error)`, `Swift.Result` or `Combine`.\n\nThe data could be written as:\n\n1. `String` that is formatted as a InfluxDB's Line Protocol\n1. [Data Point](/Sources/InfluxDBSwift/Point.swift#L11) structure\n1. Tuple style mapping with keys: `measurement`, `tags`, `fields` and `time`\n1. Array of above items\n\nThe following example demonstrates how to write data with Data Point structure. For further information see docs and [examples](/Examples).\n\n```swift\nimport ArgumentParser\nimport Foundation\nimport InfluxDBSwift\nimport InfluxDBSwiftApis\n\n@main\nstruct WriteData: AsyncParsableCommand {\n  @Option(name: .shortAndLong, help: \"The name or id of the bucket destination.\")\n  private var bucket: String\n\n  @Option(name: .shortAndLong, help: \"The name or id of the organization destination.\")\n  private var org: String\n\n  @Option(name: .shortAndLong, help: \"Authentication token.\")\n  private var token: String\n\n  @Option(name: .shortAndLong, help: \"HTTP address of InfluxDB.\")\n  private var url: String\n}\n\nextension WriteData {\n  mutating func run() async throws {\n    //\n    // Initialize Client with default Bucket and Organization\n    //\n    let client = InfluxDBClient(\n            url: url,\n            token: token,\n            options: InfluxDBClient.InfluxDBOptions(bucket: bucket, org: org))\n\n    //\n    // Record defined as Data Point\n    //\n    let recordPoint = InfluxDBClient\n            .Point(\"demo\")\n            .addTag(key: \"type\", value: \"point\")\n            .addField(key: \"value\", value: .int(2))\n    //\n    // Record defined as Data Point with Timestamp\n    //\n    let recordPointDate = InfluxDBClient\n            .Point(\"demo\")\n            .addTag(key: \"type\", value: \"point-timestamp\")\n            .addField(key: \"value\", value: .int(2))\n            .time(time: .date(Date()))\n\n    try await client.makeWriteAPI().write(points: [recordPoint, recordPointDate])\n    print(\"Written data:\\n\\n\\([recordPoint, recordPointDate].map { \"\\t- \\($0)\" }.joined(separator: \"\\n\"))\")\n    print(\"\\nSuccess!\")\n\n    client.close()\n  }\n}\n```\n- sources - [WriteData/WriteData.swift](/Examples/WriteData/Sources/WriteData/WriteData.swift)\n\n### Queries\n\nThe result retrieved by [QueryApi](/Sources/InfluxDBSwift/QueryAPI.swift#L62) could be formatted as a:\n\n1. Lazy sequence of [FluxRecord](/Sources/InfluxDBSwift/QueryAPI.swift#L258)\n1. Raw query response as a `Data`.\n\n#### Query to FluxRecord\n\n```swift\nimport ArgumentParser\nimport Foundation\nimport InfluxDBSwift\nimport InfluxDBSwiftApis\n\n@main\nstruct QueryCpu: AsyncParsableCommand {\n  @Option(name: .shortAndLong, help: \"The name or id of the bucket destination.\")\n  private var bucket: String\n\n  @Option(name: .shortAndLong, help: \"The name or id of the organization destination.\")\n  private var org: String\n\n  @Option(name: .shortAndLong, help: \"Authentication token.\")\n  private var token: String\n\n  @Option(name: .shortAndLong, help: \"HTTP address of InfluxDB.\")\n  private var url: String\n}\n\nextension QueryCpu {\n  mutating func run() async throws {\n    //\n    // Initialize Client with default Bucket and Organization\n    //\n    let client = InfluxDBClient(\n            url: url,\n            token: token,\n            options: InfluxDBClient.InfluxDBOptions(bucket: bucket, org: org))\n\n    // Flux query\n    let query = \"\"\"\n                from(bucket: \"\\(self.bucket)\")\n                    |\u003e range(start: -10m)\n                    |\u003e filter(fn: (r) =\u003e r[\"_measurement\"] == \"cpu\")\n                    |\u003e filter(fn: (r) =\u003e r[\"cpu\"] == \"cpu-total\")\n                    |\u003e filter(fn: (r) =\u003e r[\"_field\"] == \"usage_user\" or r[\"_field\"] == \"usage_system\")\n                    |\u003e last()\n                \"\"\"\n\n    print(\"\\nQuery to execute:\\n\\(query)\\n\")\n\n    let records = try await client.queryAPI.query(query: query)\n\n    print(\"Query results:\")\n    try records.forEach { print(\" \u003e \\($0.values[\"_field\"]!): \\($0.values[\"_value\"]!)\") }\n\n    client.close()\n  }\n}\n```\n- sources - [QueryCpu/QueryCpu.swift](/Examples/QueryCpu/Sources/QueryCpu/QueryCpu.swift)\n\n#### Query to Data\n\n```swift\n@main\nstruct QueryCpuData: AsyncParsableCommand {\n  @Option(name: .shortAndLong, help: \"The name or id of the bucket destination.\")\n  private var bucket: String\n\n  @Option(name: .shortAndLong, help: \"The name or id of the organization destination.\")\n  private var org: String\n\n  @Option(name: .shortAndLong, help: \"Authentication token.\")\n  private var token: String\n\n  @Option(name: .shortAndLong, help: \"HTTP address of InfluxDB.\")\n  private var url: String\n}\n\nextension QueryCpuData {\n  mutating func run() async throws {\n    //\n    // Initialize Client with default Bucket and Organization\n    //\n    let client = InfluxDBClient(\n            url: url,\n            token: token,\n            options: InfluxDBClient.InfluxDBOptions(bucket: bucket, org: org))\n\n    // Flux query\n    let query = \"\"\"\n                from(bucket: \"\\(self.bucket)\")\n                    |\u003e range(start: -10m)\n                    |\u003e filter(fn: (r) =\u003e r[\"_measurement\"] == \"cpu\")\n                    |\u003e filter(fn: (r) =\u003e r[\"cpu\"] == \"cpu-total\")\n                    |\u003e filter(fn: (r) =\u003e r[\"_field\"] == \"usage_user\" or r[\"_field\"] == \"usage_system\")\n                    |\u003e last()\n                \"\"\"\n\n    print(\"\\nQuery to execute:\\n\\(query)\\n\")\n\n    let response = try await client.queryAPI.queryRaw(query: query)\n\n    let csv = String(decoding: response, as: UTF8.self)\n    print(\"InfluxDB response: \\(csv)\")\n\n    client.close()\n  }\n}\n```\n- sources - [QueryCpuData/QueryCpuData.swift](/Examples/QueryCpuData/Sources/QueryCpuData/QueryCpuData.swift)\n\n#### Parameterized queries\nInfluxDB Cloud supports [Parameterized Queries](https://docs.influxdata.com/influxdb/cloud/query-data/parameterized-queries/)\nthat let you dynamically change values in a query using the InfluxDB API. Parameterized queries make Flux queries more\nreusable and can also be used to help prevent injection attacks.\n\nInfluxDB Cloud inserts the params object into the Flux query as a Flux record named `params`. Use dot or bracket\nnotation to access parameters in the `params` record in your Flux query. Parameterized Flux queries support only `int`\n, `float`, and `string` data types. To convert the supported data types into\nother [Flux basic data types, use Flux type conversion functions](https://docs.influxdata.com/influxdb/cloud/query-data/parameterized-queries/#supported-parameter-data-types).\n\nParameterized query example:\n\u003e :warning: Parameterized Queries are supported only in InfluxDB Cloud, currently there is no support in InfluxDB OSS.\n\n```swift\nimport ArgumentParser\nimport Foundation\nimport InfluxDBSwift\nimport InfluxDBSwiftApis\n\n@main\nstruct ParameterizedQuery: AsyncParsableCommand {\n  @Option(name: .shortAndLong, help: \"The bucket to query. The name or id of the bucket destination.\")\n  private var bucket: String\n\n  @Option(name: .shortAndLong,\n          help: \"The organization executing the query. Takes either the `ID` or `Name` interchangeably.\")\n  private var org: String\n\n  @Option(name: .shortAndLong, help: \"Authentication token.\")\n  private var token: String\n\n  @Option(name: .shortAndLong, help: \"HTTP address of InfluxDB.\")\n  private var url: String\n}\n\nextension ParameterizedQuery {\n  mutating func run() async throws {\n    // Initialize Client with default Organization\n    let client = InfluxDBClient(\n            url: url,\n            token: token,\n            options: InfluxDBClient.InfluxDBOptions(bucket: bucket, org: org))\n\n    for index in 1...3 {\n      let point = InfluxDBClient\n              .Point(\"demo\")\n              .addTag(key: \"type\", value: \"point\")\n              .addField(key: \"value\", value: .int(index))\n      try await client.makeWriteAPI().write(point: point)\n    }\n\n    // Flux query\n    let query = \"\"\"\n                from(bucket: params.bucketParam)\n                    |\u003e range(start: -10m)\n                    |\u003e filter(fn: (r) =\u003e r[\"_measurement\"] == params.measurement)\n                \"\"\"\n\n    // Query parameters [String:String]\n    let queryParams = [\"bucketParam\": \"\\(bucket)\", \"measurement\": \"demo\"]\n\n    print(\"\\nQuery to execute:\\n\\n\\(query)\\n\\n\\(queryParams)\")\n\n    let records = try await client.queryAPI.query(query: query, params: queryParams)\n\n    print(\"\\nSuccess response...\\n\")\n\n    try records.forEach { print(\" \u003e \\($0.values[\"_field\"]!): \\($0.values[\"_value\"]!)\") }\n\n    client.close()\n  }\n}\n```\n- sources - [ParameterizedQuery/ParameterizedQuery.swift](/Examples/ParameterizedQuery/Sources/ParameterizedQuery/ParameterizedQuery.swift)\n\n### Delete data\n\nThe [DeleteAPI](https://influxdata.github.io/influxdb-client-swift/Classes/DeleteAPI.html) supports deletes \n[points](https://docs.influxdata.com/influxdb/latest/reference/glossary/#point) from an InfluxDB bucket. \nUse the [DeletePredicateRequest](https://influxdata.github.io/influxdb-client-swift/Structs/DeletePredicateRequest.html) identifies which points to delete.\n\n```swift\nimport ArgumentParser\nimport Foundation\nimport InfluxDBSwift\nimport InfluxDBSwiftApis\n\n@main\nstruct DeleteData: AsyncParsableCommand {\n  @Option(name: .shortAndLong, help: \"Specifies the bucket name to delete data from.\")\n  private var bucket: String\n\n  @Option(name: .shortAndLong,\n          help: \"Specifies the organization name to delete data from.\")\n  private var org: String\n\n  @Option(name: .shortAndLong, help: \"Authentication token.\")\n  private var token: String\n\n  @Option(name: .shortAndLong, help: \"HTTP address of InfluxDB.\")\n  private var url: String\n\n  @Option(name: .shortAndLong, help: \"InfluxQL-like delete predicate statement.\")\n  private var predicate: String\n}\n\nextension DeleteData {\n  mutating func run() async throws {\n    // Initialize Client with default Organization\n    let client = InfluxDBClient(\n            url: url,\n            token: token,\n            options: InfluxDBClient.InfluxDBOptions(org: self.org))\n\n    // Create DeletePredicateRequest\n    let predicateRequest = DeletePredicateRequest(\n            start: Date(timeIntervalSince1970: 0),\n            stop: Date(),\n            predicate: predicate)\n\n    try await client.deleteAPI.delete(predicate: predicateRequest, bucket: bucket, org: org)\n\n    print(\"\\nDeleted data by predicate:\\n\\n\\t\\(predicateRequest)\")\n\n    // Print date after Delete\n    try await queryData(client: client)\n\n    client.close()\n  }\n\n  private func queryData(client: InfluxDBClient) async throws {\n    let query = \"\"\"\n                from(bucket: \"\\(bucket)\")\n                    |\u003e range(start: 0)\n                    |\u003e filter(fn: (r) =\u003e r[\"_measurement\"] == \"server\")\n                    |\u003e pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")\n                \"\"\"\n\n    let response = try await client.queryAPI.query(query: query)\n\n    print(\"\\nRemaining data after delete:\\n\")\n\n    try response.forEach { record in\n      let provider = record.values[\"provider\"]!\n      let production = record.values[\"production\"]\n      let app = record.values[\"app\"]\n      return print(\"\\t\\(provider),production=\\(production!),app=\\(app!)\")\n    }\n  }\n}\n```\n- sources - [DeleteData/DeleteData.swift](/Examples/DeleteData/Sources/DeleteData/DeleteData.swift)\n\n### Management API\n\nThe client supports following management API:\n\n|                                                                                                                         | API docs                                                             |\n|-------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|\n| [**AuthorizationsAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/AuthorizationsAPI.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Authorizations  |\n| [**BucketsAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/BucketsAPI.html)               | https://docs.influxdata.com/influxdb/latest/api/#tag/Buckets         |\n| [**DBRPsAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/DBRPsAPI.html)                   | https://docs.influxdata.com/influxdb/latest/api/#tag/DBRPs           |\n| [**HealthAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/HealthAPI.html)                 | https://docs.influxdata.com/influxdb/latest/api/#tag/Health          |\n| [**PingAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/PingAPI.html)                     | https://docs.influxdata.com/influxdb/latest/api/#tag/Ping            |\n| [**LabelsAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/LabelsAPI.html)                 | https://docs.influxdata.com/influxdb/latest/api/#tag/Labels          |\n| [**OrganizationsAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/OrganizationsAPI.html)   | https://docs.influxdata.com/influxdb/latest/api/#tag/Organizations   |\n| [**ReadyAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/ReadyAPI.html)                   | https://docs.influxdata.com/influxdb/latest/api/#tag/Ready           |\n| [**ScraperTargetsAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/ScraperTargetsAPI.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/ScraperTargets  |\n| [**SecretsAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/SecretsAPI.html)               | https://docs.influxdata.com/influxdb/latest/api/#tag/Secrets         |\n| [**SetupAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/SetupAPI.html)                   | https://docs.influxdata.com/influxdb/latest/api/#tag/Tasks           |\n| [**SourcesAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/SourcesAPI.html)               | https://docs.influxdata.com/influxdb/latest/api/#tag/Sources         |\n| [**TasksAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/TasksAPI.html)                   | https://docs.influxdata.com/influxdb/latest/api/#tag/Tasks           |\n| [**UsersAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/UsersAPI.html)                   | https://docs.influxdata.com/influxdb/latest/api/#tag/Users           |\n| [**VariablesAPI**](https://influxdata.github.io/influxdb-client-swift/Classes/InfluxDB2API/VariablesAPI.html)           | https://docs.influxdata.com/influxdb/latest/api/#tag/Variables       |\n\n\nThe following example demonstrates how to use a InfluxDB 2.0 Management API to create new bucket. For further information see docs and [examples](/Examples).\n\n```swift\nimport ArgumentParser\nimport Foundation\nimport InfluxDBSwift\nimport InfluxDBSwiftApis\n\n@main\nstruct CreateNewBucket: AsyncParsableCommand {\n  @Option(name: .shortAndLong, help: \"New bucket name.\")\n  private var name: String\n\n  @Option(name: .shortAndLong, help: \"Duration bucket will retain data.\")\n  private var retention: Int64 = 3600\n\n  @Option(name: .shortAndLong, help: \"Specifies the organization name.\")\n  private var org: String\n\n  @Option(name: .shortAndLong, help: \"Authentication token.\")\n  private var token: String\n\n  @Option(name: .shortAndLong, help: \"HTTP address of InfluxDB.\")\n  private var url: String\n}\n\nextension CreateNewBucket {\n  mutating func run() async throws {\n    // Initialize Client and API\n    let client = InfluxDBClient(url: url, token: token)\n    let api = InfluxDB2API(client: client)\n\n    let orgId = (try await api.organizationsAPI.getOrgs(org: org)!).orgs?.first?.id\n\n    // Bucket configuration\n    let request = PostBucketRequest(\n            orgID: orgId!,\n            name: name,\n            retentionRules: [RetentionRule(type: RetentionRule.ModelType.expire, everySeconds: retention)])\n\n    // Create Bucket\n    let bucket = try await api.bucketsAPI.postBuckets(postBucketRequest: request)!\n\n    // Create Authorization with permission to read/write created bucket\n    let bucketResource = Resource(\n            type: Resource.ModelType.buckets,\n            id: bucket.id,\n            orgID: orgId\n    )\n\n    // Authorization configuration\n    let authorizationRequest = AuthorizationPostRequest(\n            description: \"Authorization to read/write bucket: \\(name)\",\n            orgID: orgId!,\n            permissions: [\n              Permission(action: Permission.Action.read, resource: bucketResource),\n              Permission(action: Permission.Action.write, resource: bucketResource)\n            ])\n\n    // Create Authorization\n    let authorization = try await api.authorizationsAPI.postAuthorizations(authorizationPostRequest: authorizationRequest)!\n\n    print(\"The bucket: '\\(bucket.name)' is successfully created.\")\n    print(\"The following token could be use to read/write:\")\n    print(\"\\t\\(authorization.token!)\")\n\n    client.close()\n  }\n}\n```\n- sources - [CreateNewBucket/CreateNewBucket.swift](/Examples/CreateNewBucket/Sources/CreateNewBucket/CreateNewBucket.swift)\n\n## Advanced Usage\n\n### Default Tags\n\nSometimes is useful to store same information in every measurement e.g. `hostname`, `location`, `customer`.\nThe client is able to use static value or env variable as a tag value.\n\nThe expressions:\n- `California Miner` - static value\n- `${env.HOST_NAME}` - environment property\n\n#### Example\n\n```swift\nclient = InfluxDBClient(\n        url: \"http://localhost:8086\",\n        token: \"my-token\",\n        options: InfluxDBClient.InfluxDBOptions(bucket: \"my-bucket\", org: \"my-org\"))\n\nlet tuple: InfluxDBClient.Point.Tuple\n        = (measurement: \"mem\", tags: [\"tag\": \"a\"], fields: [\"value\": .int(3)], time: nil)\n\nlet records: [Any] = [\n        InfluxDBClient.Point(\"mining\")\n                .addTag(key: \"sensor_state\", value: \"normal\")\n                .addField(key: \"depth\", value: .int(2)),\n        tuple\n]\n\nlet defaultTags = InfluxDBClient.PointSettings()\n        .addDefaultTag(key: \"customer\", value: \"California Miner\")\n        .addDefaultTag(key: \"sensor_id\", value: \"${env.SENSOR_ID}\")\n\ntry await client.makeWriteAPI(pointSettings: defaultTags).writeRecords(records: records)\nprint(\"Successfully written default tags\")\n```\n\n##### Example Output\n\n```bash\nmining,customer=California\\ Miner,sensor_id=123-456-789,sensor_state=normal depth=2i\nmining,customer=California\\ Miner,sensor_id=123-456-789,sensor_state=normal pressure=3i\n```\n\n### Proxy and redirects\n\n\u003e :warning: The `connectionProxyDictionary` cannot be defined on **Linux**. You have to set `HTTPS_PROXY` or `HTTP_PROXY` system environment.\n\nYou can configure the client to tunnel requests through an HTTP proxy by `connectionProxyDictionary` option:\n\n```swift\nvar connectionProxyDictionary = [AnyHashable: Any]()\nconnectionProxyDictionary[kCFNetworkProxiesHTTPEnable as String] = 1\nconnectionProxyDictionary[kCFNetworkProxiesHTTPProxy as String] = \"localhost\"\nconnectionProxyDictionary[kCFNetworkProxiesHTTPPort as String] = 3128\n\nlet options: InfluxDBClient.InfluxDBOptions = InfluxDBClient.InfluxDBOptions(\n        bucket: \"my-bucket\",\n        org: \"my-org\",\n        precision: .ns,\n        connectionProxyDictionary: connectionProxyDictionary)\n\nclient = InfluxDBClient(url: \"http://localhost:8086\", token: \"my-token\", options: options)\n```\nFor more info see - [URLSessionConfiguration.connectionProxyDictionary](https://developer.apple.com/documentation/foundation/urlsessionconfiguration/1411499-connectionproxydictionary), [Global Proxy Settings Constants](https://developer.apple.com/documentation/cfnetwork/global_proxy_settings_constants/).\n\n#### Redirects\n\nClient automatically follows HTTP redirects. You can disable redirects by an `urlSessionDelegate` configuration:\n\n```swift\nclass DisableRedirect: NSObject, URLSessionTaskDelegate {\n    func urlSession(_ session: URLSession,\n                    task: URLSessionTask,\n                    willPerformHTTPRedirection response: HTTPURLResponse,\n                    newRequest request: URLRequest,\n                    completionHandler: @escaping (URLRequest?) -\u003e Void) {\n        completionHandler(nil)\n    }\n}\n\nlet options = InfluxDBClient.InfluxDBOptions(\n        bucket: \"my-bucket\",\n        org: \"my-org\",\n        urlSessionDelegate: DisableRedirect())\n\nclient = InfluxDBClient(url: \"http://localhost:8086\", token: \"my-token\", options: options)\n```\n\nFor more info see - [URLSessionDelegate](https://developer.apple.com/documentation/foundation/urlsessiondelegate).\n\n\n## Contributing\n\nIf you would like to contribute code you can do through GitHub by forking the repository and sending a pull request into the `master` branch.\n\nBuild Requirements:\n\n- swift 5.3 or higher\n\nBuild source and test targets:\n\n```bash\nswift build --build-tests\n```\n\nRun tests:\n\n```bash\n./Scripts/influxdb-restart.sh\nswift test\n```\n\nCheck code coverage:\n\n```bash\n./Scripts/influxdb-restart.sh\nswift test --enable-code-coverage\n```\n\nYou could also use a `docker-cli` without installing the Swift SDK:\n\n```bash\nmake docker-cli\nswift build\n```\n\n## License\n\nThe client is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfluxdata%2Finfluxdb-client-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfluxdata%2Finfluxdb-client-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfluxdata%2Finfluxdb-client-swift/lists"}