Skip to main content

Utility tools for Desync AI users

Project description

desync-data

Utility functions for working with PageData objects from the desync_search library. These tools help you clean, filter, deduplicate, extract links, compute text stats, and export structured data from websites crawled via Desync.


🚀 Features

  • 🔍 Remove boilerplate from page content (prefix/suffix delimiters)
  • 📌 Filter pages by URL substring
  • 🧹 Remove duplicate pages (based on text_content)
  • 🔗 Extract link graphs (internal navigation structure)
  • 📊 Compute text statistics (word count, link density, etc.)
  • 📤 Export pages to CSV, JSON, or SQLite

📦 Installation

pip install desync-data

🧪 Quick Example

from desync_search import DesyncClient
from desync_data import *

client = DesyncClient(api_key="your_api_key")
pages = client.crawl("https://example.com", max_depth=2)

pages = remove_duplicate_pages(pages)
pages = remove_boilerplate_prefix(pages, "START")
pages = remove_boilerplate_suffix(pages, "FOOTER")
pages = filter_by_url_substring(pages, "/team")

save_to_csv(pages, "pages.csv")
save_to_json(pages, "pages.json")
save_to_sqlite(pages, "pages.sqlite")

edges = extract_link_graph(pages)
for stat in map(compute_text_stats, pages):
    print(stat)

📚 Function Documentation

remove_boilerplate_prefix(pages, delimiter)

Removes everything before and including the first occurrence of the given delimiter in text_content for each page.

  • pages: list of PageData-like objects
  • delimiter: string to match and cut before
  • Returns: cleaned list of modified objects

remove_boilerplate_suffix(pages, delimiter)

Removes everything after and including the first occurrence of the delimiter in text_content.

  • pages: list of PageData-like objects
  • delimiter: string to cut after
  • Returns: cleaned list

remove_duplicate_pages(pages)

Eliminates duplicates based on exact text_content. Keeps the first appearance.

  • Returns: list with duplicates removed

filter_by_url_substring(pages, substring)

Keeps only pages whose url contains the given substring.

  • substring: required URL fragment to retain
  • Returns: filtered list of pages

extract_link_graph(pages, include_external_links=False, only_include_crawled_pages=False)

Returns a list of (source_url, destination_url) pairs based on the internal_links field.

  • include_external_links: if False, skip links to other domains
  • only_include_crawled_pages: if True, limit to known pages only
  • Returns: list of directed edges

compute_text_stats(page)

Calculates basic content metrics:

  • word_count: total words in text_content
  • sentence_count: count of ., !, ?
  • unique_word_ratio: unique words / total words
  • link_density: words inside <a> tags / total words

Returns: dictionary with all metrics
Requires: beautifulsoup4


save_to_csv(pages, filepath, mode="w")

Writes selected fields to a .csv file.

  • filepath: output path
  • mode: "w" for overwrite, "a" for append
  • Fields: url, domain, timestamp, text_content, etc.

save_to_json(pages, filepath, mode="w")

Saves all pages as a list of dictionaries to a .json file.

  • mode: "w" or "a" (appends if file exists and is valid)

save_to_sqlite(pages, db_path, table_name="pages", append=True)

Saves all records to a local SQLite database.

  • db_path: file path for .sqlite
  • append: if False, drops and recreates table
  • table_name: optional table name override

🔧 Requirements

  • Python 3.7+
  • desync_search
  • beautifulsoup4 (for text stat parsing)

Install with:

pip install desync-data

🧑‍💻 Author

Created by Jackson Ballow for fast and scalable web content processing using Desync.


📄 License

MIT License

Project details


Download files

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

Source Distribution

desync_data-0.1.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

desync_data-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file desync_data-0.1.1.tar.gz.

File metadata

  • Download URL: desync_data-0.1.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for desync_data-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a504b9c4d4351c65c4fd101a017d9ba4f04d461396d3bbb21c3eb06d4a72ee0f
MD5 7441d3beac9db25ab3d5a5a53325a647
BLAKE2b-256 930cb7f68dc202e00350c1f697079a7bc06b87c3976f23b819a5fc53fc402443

See more details on using hashes here.

File details

Details for the file desync_data-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: desync_data-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for desync_data-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a5ac318f03802a0c91bbc1a5b801bbc104b82ef60cb5a40572c56ee2310900f6
MD5 305bcc0c770726e77a77333e542f877f
BLAKE2b-256 0d5a6913a3ef615bfd3b0b5d854ef3f7345d86acfac499ab9ab93f2f2434d848

See more details on using hashes here.

Supported by

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