Skip to main content

Python library that handles token authentication for MuckRock and DocumentCloud

Project description

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.
  • 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"]

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_squarelet-0.0.7.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

python_squarelet-0.0.7-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_squarelet-0.0.7.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for python_squarelet-0.0.7.tar.gz
Algorithm Hash digest
SHA256 0f759edb731f978308e481238137c4031f88ea9c14110692ea7ed60dda6381f5
MD5 c2575961d0b06175d33926cf4fe2b689
BLAKE2b-256 37b9096863c2037eca180d31d47c031ec730959dcd2b56411c2a408774661a5e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_squarelet-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d125ef602c2a23c9668c8ecc0f5312b865b63534588b5559debd45fca19baaec
MD5 4e8f31cb85681e40198867a7d16278d4
BLAKE2b-256 ba0ebfc389f96130cbd5e202e11034bb047e60331dd3e71717983f9331b58ba5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page