Skip to main content

icalendar-searcher

This library should contain logic for searching, filtering and sorting icalendar data, as well as logic for storing and representing an icalendar search query.

Audience

  • This will be used for the python CalDAV client library, both for bundling search parameters together in one object, for doing client-side filtering when the server does not support the desired search query.
  • This may be useful in any kind of software handling collections of calendar content and needing to do filtering or searches on it.
  • This may also be useful by calendar server developers.

Maturity

I've decided to release 1.0 now as I think it's getting more or less feature-complete (with the exception of advanced operators). However, the library has not been battle-tested.

sort and check_component is used by the caldav project. It has not been used much in the wild yet, but they have been through some QA and is also tested by test-code from the caldav project.

filter, filter_calendar and sort_calendar has not been tested yet, is AI-generated and is only covered by AI-generated test code. There may be dragons.

Maturity

I've decided to release 1.0 now as I think it's getting more or less feature-complete (with the exception of advanced operators). The API is considered stable and will follow semantic versioning going forward.

sort and check_component is used by the caldav project, it has not been used much in the wild yet, but has been through quite some testing.

filter, filter_calendar and sort_calendar has not been tested yet, is AI-generated and is only covered by AI-generated test code. There may be dragons.

Not yet implemented: operators like !=, <>, <, <=, >, >=, ~ (regex), etc.

Usage

No proper usage documentation has been written yet, sorry. There are tons of inline comments and docstrings though. The AI has contributed with quite some verbose comments in the test code, but little of it has been exposed to any proper QA.

Basic Example

from icalendar_searcher import Searcher
from datetime import datetime

# Create a searcher with filters
searcher = Searcher(
    event=True,  # Only events
    start=datetime(2025, 1, 1),
    end=datetime(2025, 12, 31)
)

# Add property filters
searcher.add_property_filter("SUMMARY", "meeting", operator="contains")
searcher.add_property_filter("LOCATION", "Office", operator="contains", case_sensitive=False)

# Check if a single component matches
result = searcher.check_component(calendar)

# Filter a list of components
calendars = [cal1, cal2, cal3]
matching = searcher.filter(calendars)

# Sort components
searcher.add_sort_key("DTSTART")
sorted_calendars = searcher.sort(calendars)

Case-Sensitive vs Case-Insensitive Filtering

By default, text filtering is case-sensitive. You can make it case-insensitive:

# Case-insensitive search (simple API)
searcher.add_property_filter("SUMMARY", "meeting", case_sensitive=False)

# Case-sensitive search (default)
searcher.add_property_filter("SUMMARY", "Meeting")

Case-insensitivity is not straight-forward. It may cause non-deterministic sort results, and there may be problems with unicode characters - i.e., according to the CalDAV standard, case-insensitivity should only apply to ASCII-characters - causing mismatches between naïve and NAÏVE, cliché and CLICHÉ, smörgåsbord and SMÖRGÅSBORD, not to forget millions of words in non-English languages, complete non-latin scripts, etc. By default this library in itself handles Unicode relatively well - but for CalDAV searches, one may experience that case-insensitivity only applies to ASCII letters.

Category Filtering

Two virtual properties are available for filtering by categories:

  • "categories" (plural): Categories is considered to be a set of categories to be matched with the set of categories found in the event. If categories is given as a string, it will be split by the commas.
  • "category" (singular): Category is considered to be a string, to be matched literally towards at least one of the categories in the event.

Examples:

# Match events with both "WORK" and "URGENT" categories (exact match)
searcher.add_property_filter("categories", "WORK,URGENT", operator="contains")

# Match events where any category contains "out" (e.g., "outdoor", "outing")
searcher.add_property_filter("category", "out", operator="contains")

Advanced Collation (requires PyICU)

For advanced Unicode and locale-aware text comparison, install with:

pip install 'icalendar-searcher[collation]'

Locale-specific collation is useful for proper handling of language-specific characters:

from icalendar_searcher.collation import Collation

# Turkish locale: İstanbul matches "istanbul" (Turkish İ → i)
searcher.add_property_filter("LOCATION", "istanbul",
                            collation=Collation.LOCALE,
                            locale="tr_TR",
                            case_sensitive=False)

# Without Turkish locale, İstanbul won't match "istanbul"
searcher.add_property_filter("LOCATION", "istanbul",
                            collation=Collation.UNICODE,
                            case_sensitive=False)  # Won't match İstanbul

# Locale-aware sorting (e.g., Norwegian sorts æ, ø, å after z)
searcher.add_sort_key("SUMMARY", collation=Collation.LOCALE, locale="nb_NO")
  • The project depends on the icalendar library, all calendar contents handled by this library is coming in and out as icalendar.Component or icalendar.Calendar. However, the library should also support wrapped objects (like instances of the caldav.Event class).
  • The project depends on the recurring-ical-events library for expanding recurrence sets.
  • The project is used by the Python CalDAV client library

History

This is a spin-off from the python caldav project, started by Tobias Brox in 2025-11, the maintainer of the Python CalDAV client library at that time, in collaboration with the main contributors of the icalendar library.

AI

The author has been experimenting a bit with AI usage while creating this project, both GitHub Copilot and Claude has been tested. Most of the test code has been created by the AI. AI has also been utilized a bit for refactoring, bug hunting, and a little bit code generation (particularly wrg of the collations support), but most of the "business logic" was written by me.

While all the AI-generated changes in the business logic has been looked through thoroughly, very little QA has been done on the test code.

Performance

In the early versions, the filter method will take the calendar contents one by one and check if it matches or not. This will work out well enough for small calendar sets. If lots of searches are to be done on fairly static data (like what typically may happen at the server side in a calendaring system), then it would be an idea to add indexes.

The expansion part may cause millions of recurrences to be created. It even supports open-ended intervals. It's possible by returning generators. However, things will most likely blow up and eat all the CPU and memory it gets the hands on whenever one wants to do sorting of such a thing.

License

As for now I'm releasing this under the GNU Affero General Public License v.3.0. If you find this too restrictive or if this causes license compatibility issues for you, I will consider to fix some dual licensing, like it's done with the python CalDAV library.

This also means that any contributor has to accept that the code is released under AGPL v3.0 and at some point in the future may be dual-licensed under some more permissive license, like the EUPL v1.1.

I don't have very strong opinions on licenses. If you have any issues in one way or another, please reach out.

Metadata

Release files for icalendar-searcher 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for icalendar-searcher 1.0.7
File Size Uploaded
icalendar_searcher-1.0.7.tar.gz 92.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for icalendar-searcher 1.0.7
File Interpreter ABI Platform
icalendar_searcher-1.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 132.0 kB

Release files / icalendar_searcher-1.0.7.tar.gz

Download URL icalendar_searcher-1.0.7.tar.gz
Size 92.0 kB
Tags Source
SHA-256 checksum
How to use checksums
779a936391c8bf63c4591bf0f307be5a3a7b65fb4f22bde616eaaf613f3f5b1f
BLAKE2b-256 checksum
How to use checksums
371dceda7062974b92a731770b7b93cf0be24cd0ef74ed31c369bfea6f339289
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.

Transparency log

Release files / icalendar_searcher-1.0.7-py3-none-any.whl

Download URL icalendar_searcher-1.0.7-py3-none-any.whl
Size 40.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
91406dcc63eeb7bc2c5614feec8f98a0bc9263040efd288deefbbff32c57905e
BLAKE2b-256 checksum
How to use checksums
3565392c0fd2e7782e05475da248f3c7039469397be88ae21c37b9755b7948f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.

Transparency log

Release history Release notifications | RSS feed

1.2.0

2 release files

1.1.0

2 release files

1.0.8

2 release files

This release

1.0.7 This release

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.3

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.3.1

2 release files

0.2.0

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.7

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page