Python client library : problem with writing new point in the bucket

Hi there,

I’m using API get request to pull raw data from server , then fetch needed information and i use influxDB python client library to push data to my InfluxDB bucket.

The problem is each time value changes of varibale , the record of DB changes (timestamp and value updates). I want to have a new point (with different tiemstamp and value from previous one) each time this happens.

client = influxdb_client.InfluxDBClient(
    url=url,
    token=token,
    org=org,
    verify_ssl=False
    )

write_api = client.write_api(write_options=SYNCHRONOUS)

p = influxdb_client.Point(name_machine).tag(name_machine , name_machine).field("TCNZ1B3", TCNZ1B3)
write_api.write(bucket='twgdb', org=org, record=p)


any idea how to do this ? is there a way to write new point instead of updating previous one ?

Add a unique timestamp to create a new record instead of updating the existing one that way, InfluxDB will treat each point as a separate entry due to the different timestamps. Code changes you should try to make and test:

# Get current timestamp at microsecond precision if you prefer
current_time = int(datetime.utcnow().timestamp() * 1e9)

p = (
    influxdb_client.Point(name_machine)
    .tag(name_machine, name_machine)
    .field("TCNZ1B3", TCNZ1B3)
    .time(current_time)
)
write_api.write(bucket='twgdb', org=org, record=p)

Thanks for your answer. I will test this. If i need to write 4 different variables (fields) per timestamp , do i need to write each point seperatly ? is it possible to write all data points in 1 batch using python client library ?

Really up to you, you can pass multiple points in a single list, something like this : write_api.write(bucket='twgdb', org=org, record=[p1, p2, p3])

tha’s what i did but ended up with “failed to load tags” error
image