Skip to main content

Reverse engineered Fragment API that mimics the official webclient

Project description

python-fragment

GitHub license PyPi package version Supported python versions

An unofficial Python library for interacting with Fragment. The library scrapes Fragment's HTML pages and exposes a clean, fully typed interface.

Features

  • Both synchronous and asynchronous clients
  • Fast HTML parsing powered by selectolax
  • Fully typed - all returned data is described with TypedDict schemas
  • Automatic retries on network failures with exponential back-off

Installation

pip install python-fragment

Requirements: Python 3.9+

Quick Start

Async client

import asyncio
import fragment

async def main():
  async with fragment.AsyncClient() as client:
    # Search usernames currently on auction
    usernames = await client.search_usernames(
      query="crypto",
      filter="auction",
      sort="price_desc"
    )
    for u in usernames[:3]:
      print(u)
      # {
      #   'username': 'crypto',
      #   'status': 'auction',
      #   'value': 15000.0,
      #   'datetime': '2024-08-01T12:00:00+00:00',
      #   'is_resale': False
      # }

asyncio.run(main())

Sync client

import fragment

with fragment.Client() as client:
  # Detailed info for a specific username
  info = client.username_info("durov")
  print(info["status"])
  print(info["bid_history"])
  print(info["ownership_history"])

Proxy Usage

Both clients forward **request_kwargs directly to the underlying HTTP library, so proxies are configured per-call.

Async client (aiohttp)

Pass a single proxy URL string via the proxy keyword argument:

import asyncio
import fragment

PROXY = "http://{user}:{password}@{host}:{port}"

async def main():
  async with fragment.AsyncClient() as client:
    print(await client.username_info("crypto", proxy=PROXY))

asyncio.run(main())

Sync client (requests)

Pass a proxies dict that maps URL schemes to the proxy URL:

import fragment

PROXY = "http://{user}:{password}@{host}:{port}"

with fragment.Client() as client:
  print(client.username_info("crypto", proxies={"http": PROXY, "https": PROXY}))

Error Handling

import fragment
from fragment.errors import FragmentHTTPError, ParserError


async with fragment.AsyncClient() as client:
  try:
    info = await client.username_info("someusername")
  except FragmentHTTPError as e:
    print(f"HTTP error: {e}")
  except ParserError as e:
    print(f"Failed to parse Fragment HTML: {e}")

FragmentHTTPError - raised when the server returns a non-OK response.

ParserError - raised when the Fragment page structure has changed and data cannot be extracted.

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

python_fragment-0.4.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

python_fragment-0.4.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file python_fragment-0.4.0.tar.gz.

File metadata

  • Download URL: python_fragment-0.4.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.12.3 HTTPX/0.28.1

File hashes

Hashes for python_fragment-0.4.0.tar.gz
Algorithm Hash digest
SHA256 e95ea1afa2ace3f85afe5af49566f7bfa654f3603fc18968372f60097acca1ed
MD5 cdd2b9940f8f6bd5373f1a34794a7249
BLAKE2b-256 093cda453bc042e300b730c3b5260ec3d22cf114e436a4d21fe31a3f79989eb7

See more details on using hashes here.

File details

Details for the file python_fragment-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: python_fragment-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.12.3 HTTPX/0.28.1

File hashes

Hashes for python_fragment-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34ab2788377dbed86f509e810d59a088b1610ad80d1ae42f986ff826d00fdd17
MD5 80eeea1cf8c32f3d7a5e356b40e3b0d5
BLAKE2b-256 7b33f5a47f2eca1c3e8616bb06aa4c129d33575e1bea850c2020e0ee255b1075

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