Skip to main content

python-squarelet

A Python wrapper for Squarelet, allowing for authentication with MuckRock systems like MuckRock Requests and DocumentCloud.

Features

  • Token-based Authentication: Easily authenticate with MuckRock services using username/password or refresh tokens.
  • Rate Limiting: Automatically applies rate limiting to prevent exceeding API request limits.
  • Automatic Token Refresh: Seamlessly refresh your access tokens when expired without manual intervention. It detects that your access token is about to expire before making the request so it eagerly refreshes.
  • Retry Logic: Built-in automatic retries for failed requests, ensuring robust interaction with MuckRock services.
  • API Request Handling: Send GET, POST, PUT, DELETE, and other HTTP requests to MuckRock’s API with an easy-to-use interface.
  • Customizable Request Headers: Extend or modify request parameters (like headers) through flexible client configuration.
  • Error Handling: Provides detailed error handling with custom exceptions for API errors, credentials issues, and missing resources.

Installation

$ pip install python-squarelet

Usage

# If you intend on accessing MuckRock requests, the base_uri would be https://www.muckrock.com/api_v1/ or https://www.muckrock.com/api_v2/
base_uri="https://api.www.documentcloud.org/api/"
from squarelet import SquareletClient
# Authenticating with Squarelet using your credentials
client = SquareletClient(base_uri=base_uri, username="your_username", password="your_password")
# Example API call that gets data about your DocumentCloud account.
my_user = client.request("get", "users/me/")
# Print the response data about your DocumentCloud account. 
print(my_user.text) 

Generally, it is safer to access your username as local environment variables using os.environ instead of specifying your username and password as strings, especially if publishing this code anywhere. After setting your local environment variables SQ_USERNAME and SQ_PASSWORD with your credentials, you can access them like so.

username = os.environ["SQ_USERNAME"]
password = os.environ["SQ_PASSWORD"]

Running tests

You can run tests from the project root by running:

$ pytest src/squarelet/tests.py

Download files

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

Source Distribution

python_squarelet-0.5.0.tar.gz (19.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_squarelet-0.5.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file python_squarelet-0.5.0.tar.gz.

File metadata

  • Download URL: python_squarelet-0.5.0.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.18

File hashes

Hashes for python_squarelet-0.5.0.tar.gz
Algorithm Hash digest
SHA256 bf3d5ff191056fd978ea4c3e33f967a54fefc18a2c550b23100cb05079eeeda6
MD5 9a43aa88b825c9a82eddd389f058fec9
BLAKE2b-256 54f986c201c8e0c6fccc64cc07f607f6017b6980f69c156c3d5c82642162ff8a

See more details on using hashes here.

File details

Details for the file python_squarelet-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_squarelet-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4d33df3f940396f51fc4b6d545aebf9f3e7c8ecee769c30001996c5a87d25ef
MD5 d56d310d38e6ac065ecee2f0716c47be
BLAKE2b-256 9d24bcc1122f6cde53fae7e9636d2ee286dc7b29457724c9ba9b2923b7baf0b1

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.0

2 files

0.5.1

2 files

This release

0.5.0 This release

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page