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.1.tar.gz (8.2 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.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_fragment-0.4.1.tar.gz
  • Upload date:
  • Size: 8.2 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.1.tar.gz
Algorithm Hash digest
SHA256 0b36aa3df955556b475fd1c0d2d2e1b103de9e613d052fd96923842f6c89ca9f
MD5 bc396e0f1bc9c739b80831c29fa206a2
BLAKE2b-256 e471b2181446e6fe5149108e3dfcb56488a3f5758648f2ee98f6e7cca0bfacbe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_fragment-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d55047a9892e989204df22c06ec3c369c8ab8c433cb767480614e62cc59b33c
MD5 ca1ae69ae0b0712249c6f17c7357d300
BLAKE2b-256 7de8fc1c50037b07512b45f0b2ee839e61780a023670e9108e67b35119ed8fb4

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