python-fragment
An unofficial Python library for interacting with Fragment (Python 3.9+). 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
TypedDictschemas - Automatic retries on network failures with exponential back-off
Installation
pip install python-fragment
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
A proxy can be set for the entire client session or overridden per individual request. The interface is identical for both AsyncClient and Client.
Client-level proxy
import fragment
PROXY = "http://{user}:{password}@{host}:{port}"
# Async
async with fragment.AsyncClient(proxy=PROXY) as client:
print(await client.username_info("crypto"))
# Sync
with fragment.Client(proxy=PROXY) as client:
print(client.username_info("crypto"))
Per-request proxy
import fragment
PROXY = "http://{user}:{password}@{host}:{port}"
# Async
async with fragment.AsyncClient() as client:
print(await client.username_info("crypto", proxy=PROXY))
# Sync
with fragment.Client() as client:
print(client.username_info("crypto", proxy=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.
Metadata
Release files for python-fragment 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_fragment-0.4.2.tar.gz | 8.3 kB | Without provenance | Details for python_fragment-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_fragment-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for python_fragment-0.4.2-py3-none-any.whl |
Total release size: 19.4 kB
Release files / python_fragment-0.4.2.tar.gz
| Download URL | python_fragment-0.4.2.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a9c515e495a963a6f689103fb692619166371212f5e0240a436abbf3ff288d5a
|
|
BLAKE2b-256 checksum How to use checksums |
4331447b4683bae179c0c92a5279a982b7a39da6d1ed3ab142124b00b2f71f66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.5 cpython/3.12.3 HTTPX/0.28.1
|
Release files / python_fragment-0.4.2-py3-none-any.whl
| Download URL | python_fragment-0.4.2-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c8c27993aa738bac1731d3eb528f221bcdab327c705b86cfc1427944ea614f36
|
|
BLAKE2b-256 checksum How to use checksums |
8653636d1d2ba9d9ddb95174cfa273ab69b43be870f43487d41b2eb431fc3754
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.5 cpython/3.12.3 HTTPX/0.28.1
|
Security for python-fragment 0.4.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.