Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PyTrendy Logo

PyTrendy

PyPI version Python License: MIT
Tests Release
codecov Downloads

PyTrendy is a robust solution for identifying and analysing trends in time series. Unlike other trend detection packages, it is robust to noisy and flat segments, and handles gradual and abrupt trend cases with high precision. It aims to be the best package for trend detection in Python.

Read more in the documentation: russellsb.github.io/pytrendy/main

Why PyTrendy?

Most time series tools give you either a "trend component" (via decomposition) or "changepoints" (the moments of shift). PyTrendy is built for automated trend detection, answering what trends existed, how strong were they, and when did they start and end?

  • Beyond step changes - ruptures is the gold standard for abrupt shifts, but it doesn't handle gradual slope changes (digital marketing, stocks, energy). PyTrendy detects both in a single run.
  • The flat/noise problem - closest peers (pytrendseries, trendet, tstrends) over-fit trends on flat or noisy periods. PyTrendy's signal-processing and post-processing logic ensures trends are only detected when they are precise and valid.
  • Strategic value - where dozens of time series interact, knowing how they align or confound at specific times is invaluable for experiment design.

Features

Quickstart

Install the package from PyPi.

pip install pytrendy

Import pytrendy, and apply trend detection on daily time series data.

import pytrendy as pt
df = pt.load_data('series_synthetic')
results = pt.detect_trends(df, date_col='date', value_col='gradual', plot=True)
results.print_summary()

Detected: 
- 3 Uptrends. 
- 3 Downtrends.
- 2 Flats.
- 0 Noise.

The best detected trend is Down between dates 2025-05-09 - 2025-06-17

Full Results:
-------------------------------------------------------------------------------
            direction       start         end  days  total_change  change_rank trend_class
time_index                                                                               
1                 Up  2025-01-02  2025-01-24    22     14.013348            5     gradual
2               Down  2025-01-25  2025-02-05    11    -13.564214            6     gradual
3               Flat  2025-02-06  2025-02-09     3     -1.168831            8         NaN
4                 Up  2025-02-10  2025-03-17    35     26.190476            3     gradual
5               Down  2025-03-18  2025-04-01    14    -22.721861            4     gradual
6                 Up  2025-04-02  2025-05-08    36     72.611833            2     gradual
7               Down  2025-05-09  2025-06-17    39    -73.253968            1     gradual
8               Flat  2025-06-18  2025-06-30    12      3.910534            7         NaN
-------------------------------------------------------------------------------

Explore the strongest uptrends:

results.filter_segments(direction='Up', sort_by='change_rank')[:3]
time_index direction start end trend_class change pct_change days total_change SNR change_rank
7 Up 2025-04-02 2025-05-08 gradual 72.61 367.50% 36 72.61 21.70 2
4 Up 2025-02-10 2025-03-17 gradual 26.19 179.93% 35 26.19 18.61 3
1 Up 2025-01-02 2025-01-24 gradual 14.01 104.41% 22 14.01 22.21 5

filter_segments ranks segments by magnitude (change_rank). See the API reference for all filter and sort options.

For the full per-segment metrics table, use results.df.

For more examples on interpreting the results, see Detect Gradual Trends.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytrendy-1.4.0.dev3.tar.gz (36.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytrendy-1.4.0.dev3-py3-none-any.whl (44.5 kB view details)

Uploaded Python 3

File details

Details for the file pytrendy-1.4.0.dev3.tar.gz.

File metadata

  • Download URL: pytrendy-1.4.0.dev3.tar.gz
  • Upload date:
  • Size: 36.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pytrendy-1.4.0.dev3.tar.gz
Algorithm Hash digest
SHA256 45a59e35a9e4ed5ecc4a6a44f5bece3a01a6839f97dbc6de1f4f6af8156227fa
MD5 4da5c23ff557b054b37cd0342f76f597
BLAKE2b-256 60f312fdca0d980cfdb121cb34f4e685e68c38be95df214471e5f5c7a7674863

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytrendy-1.4.0.dev3.tar.gz:

Publisher: release.yaml on RussellSB/pytrendy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytrendy-1.4.0.dev3-py3-none-any.whl.

File metadata

  • Download URL: pytrendy-1.4.0.dev3-py3-none-any.whl
  • Upload date:
  • Size: 44.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pytrendy-1.4.0.dev3-py3-none-any.whl
Algorithm Hash digest
SHA256 24218815d39c5fde46ab197941b1b90a01342bd8f6517e2a98fe089ae1da8d48
MD5 6b4a33dfdc410b3f0153894419c506d8
BLAKE2b-256 e8c3387642d5191ce628a8f18709fabefc3f665851cb9e380d0bd68d38e33b60

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytrendy-1.4.0.dev3-py3-none-any.whl:

Publisher: release.yaml on RussellSB/pytrendy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.4.0.dev3 This release

2 files

1.3.1

2 files

1.3.0

2 files

1.2.0

2 files

1.1.11

2 files

1.1.10

2 files

1.1.9

2 files

1.1.8

2 files

1.1.7

2 files

1.1.6

2 files

1.1.5

2 files

1.1.4

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.5

2 files

0.0.4

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page