Skip to main content

Python client for the Ravelry REST API

Project description

ravelpy

License: MIT Python 3.11+

Python client for the Ravelry REST API, supporting read-only Basic Auth (public catalog data), personal account keys (full authenticated access), and OAuth 2.0 (scoped delegated access).


Install

pip install ravelpy

To also run the optional Swagger UI server:

pip install "ravelpy[server]"

Auth

Ravelry supports three credential tiers:

Tier Credential Access
Read-only Basic Auth with read- prefix username Public catalog data only
Personal key Basic Auth with your developer credentials Full authenticated access; all OAuth scopes granted automatically
OAuth 2.0 Bearer token Scoped delegated access; requires explicit scope grants

Get your developer credentials from ravelry.com/pro/developer.

Basic Auth (read-only or personal key)

Set credentials as environment variables (or in a .env file):

RAVELRY_USERNAME=read-xxxxxxxxxxxx   # or your personal username
RAVELRY_API_KEY=your_api_key
from ravelpy import RavelryClient

# Read-only key — public catalog data only
client = RavelryClient(username="read-xxxxxxxxxxxx", api_key="your_api_key")

# Personal key — full authenticated access, all scopes auto-granted
client = RavelryClient(username="your_username", api_key="your_personal_key")

OAuth 2.0

from ravelpy import RavelryClient
from ravelpy.oauth import OAuthClient, OAuthScope

oauth = OAuthClient(
    client_id="your_client_id",
    client_secret="your_client_secret",
)

# Build an auth URL and redirect the user there
url, state = oauth.auth_url(scopes=[OAuthScope.OFFLINE])

# After the user grants access, exchange the code for a token
token = oauth.exchange_code(code="the_code_from_callback")

# Build a RavelryClient from the access token
client = RavelryClient.from_oauth_token(token.access_token)

See docs/authentication.md for the full OAuth scope list, a tested scope matrix, and notes on which endpoints require specific scopes.


Quickstart

All endpoints are accessed through sub-client attributes on RavelryClient:

from ravelpy import RavelryClient

client = RavelryClient(username="read-xxxxxxxxxxxx", api_key="your_api_key")

# Search for free sock patterns
data, etag, raw = client.patterns.search(query="socks", weight="fingering", availability="free")
for p in raw["patterns"]:
    print(p["name"])

# Get a specific yarn
data, etag, raw = client.yarns.show(yarn_id=90897)
print(raw["yarn"]["name"])

# Look up your own profile (requires personal key or OAuth)
personal_client = RavelryClient(username="your_username", api_key="your_personal_key")
data, etag, raw = personal_client.people.me()
print(raw["user"]["username"])

ETag caching

Every method returns (model, etag, raw_dict). Pass the etag back on subsequent calls — the server returns 304 Not Modified and both model and raw_dict will be None.

data, etag, raw = client.patterns.search(query="socks")

# later...
data, etag, raw = client.patterns.search(query="socks", etag=etag)
if data is None:
    print("not modified — use cached data")

API coverage

Sub-client Methods
client.patterns search, show, list (multi-get), comments, highlights, projects
client.pattern_sources show, search, patterns
client.yarns show, list (multi-get), search, comments
client.yarn_companies search
client.reference color families, fiber attributes/categories, yarn weights/attributes, pattern attributes/categories, pattern source types, languages, photo sizes
client.people me, show, comments
client.projects search, list, show, comments, crafts, statuses
client.stash list, search, unified_list, show, comments
client.queue list, show
client.favorites list, show
client.fiber show, comments
client.bundles list, show, bundled_items, packs
client.shops search, show
client.groups search
client.stores list, products, purchases
client.forums sets, topics, filtered_topics, post, unread_posts
client.topics show, posts
client.messages list, show
client.needles list, sizes, types
client.designers show
client.products show, attachments
client.deliveries list
client.drafts list, show
client.volumes show
client.pages show
client.packs show
client.friends list, activity
client.library search
client.saved_searches list
client.app config, data
client.extras color_families, search
client.photos dimensions, sizes, status

Swagger UI server

The examples/server.py FastAPI proxy exposes all endpoints with interactive docs:

uvicorn examples.server:app --reload

Open http://localhost:8000/docs.


Links

License

MIT — see 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

ravelpy-0.1.0.tar.gz (722.7 kB view details)

Uploaded Source

Built Distribution

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

ravelpy-0.1.0-py3-none-any.whl (51.2 kB view details)

Uploaded Python 3

File details

Details for the file ravelpy-0.1.0.tar.gz.

File metadata

  • Download URL: ravelpy-0.1.0.tar.gz
  • Upload date:
  • Size: 722.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ravelpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8fce387232135b363407f6d6e20817537cc466d642957fa79fbf9bba837db568
MD5 c90eafe1053ef8d34253e22d060700d1
BLAKE2b-256 45361a03fdb2ddf232b35debea2749a10f1731ffff9b1f92cfc81909b5ebe8af

See more details on using hashes here.

Provenance

The following attestation bundles were made for ravelpy-0.1.0.tar.gz:

Publisher: publish.yml on weftmark/ravelpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ravelpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ravelpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 51.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ravelpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4338c35e7fa6cc26ed5f0a15edfe55d6c20360b2308e1a1beef69a8efd22399c
MD5 6cba71b1d07d57dfb2264e15ac2ead0e
BLAKE2b-256 67068e622ecb1e933557e4c009f35245098585e9e4a72966c1e57121848844d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for ravelpy-0.1.0-py3-none-any.whl:

Publisher: publish.yml on weftmark/ravelpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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