Skip to main content

Client SDK for Objectstore, the Sentry object storage platform

Project description

Objectstore Client

The client is used to interface with the objectstore backend. It handles responsibilities like transparent compression, and making sure that uploads and downloads are done as efficiently as possible.

Usage

import datetime

import urllib3

from objectstore_client import (
    Client,
    NoOpMetricsBackend,
    Permission,
    TimeToIdle,
    TimeToLive,
    TokenGenerator,
    Usecase,
)

# Necessary when using Objectstore instances that enforce authorization checks.
token_generator = TokenGenerator(
    "my-key-id",
    "<securely inject EdDSA private key>",
    expiry_seconds=60,
    permissions=Permission.max(),
)

# This should be stored in a global variable and reused, in order to reuse the connection
client = Client(
    "http://localhost:8888",
    # Optionally, bring your own metrics backend to record things like latency, throughput, and payload sizes
    metrics_backend=NoOpMetricsBackend(),
    # Optionally, enable distributed traces in Sentry
    propagate_traces=True,
    # Optionally, set timeout and retries
    timeout_ms=500, # 500ms timeout for requests
    retries=3,      # Number of connection retries
    # For further customization, provide additional kwargs for urllib3.HTTPConnectionPool
    connection_kwargs={"maxsize": 10},
    # Optionally, provide a token generator for Objectstore instances with authorization enforced
    token_generator=token_generator,
)

# This could also be stored in a global/shared variable, as you will deal with a fixed number of usecases with statically defined defaults
my_usecase = Usecase(
    "my-usecase",
    # Optionally, define defaults for all operations within this Usecase
    expiration_policy=TimeToLive(datetime.timedelta(days=1)),
)

# Start a Session, tied to your Usecase and a Scope.
# A Scope is a (possibly nested) namespace within Objectstore that provides isolation within a Usecase.
# The Scope is given as a sequence of key-value pairs through kwargs.
# Note that order matters!
# The admitted characters for keys and values are: `A-Za-z0-9_-()$!+*'`.
# You're encouraged to use the organization and project ID as the first components of the scope, as follows:
session = client.session(
    my_usecase, org=42, project=1337, app_slug="email_app"
)

# The following operations will raise an exception on failure

# Write an object and metadata
object_key = session.put(
    b"Hello, world!",
    # You can pass in your own key for the object to decide where to store the file.
    # Otherwise, Objectstore will pick a key and return it.
    # A put request to an existing key overwrites the contents and metadata.
    # key="hello",
    metadata={"key": "value"},
    # Overrides the default defined at the Usecase level
    expiration_policy=TimeToIdle(datetime.timedelta(days=30)),
)

# Read an object and its metadata
result = session.get(object_key)

content = result.payload.read()
assert content == b"Hello, world!"
assert result.metadata.custom["key"] == "value"

# Delete an object
session.delete(object_key)

Development

Environment Setup

The considerations for setting up the development environment that can be found in the main README apply for this package as well.

Pre-commit hook

A configuration to set up a git pre-commit hook using pre-commit is available at the root of the repository.

To install it, run

pre-commit install

The hook will automatically run some checks before every commit, including the linters and formatters we run in CI.

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

objectstore_client-0.0.15.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

objectstore_client-0.0.15-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file objectstore_client-0.0.15.tar.gz.

File metadata

  • Download URL: objectstore_client-0.0.15.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for objectstore_client-0.0.15.tar.gz
Algorithm Hash digest
SHA256 17d6c941cafa5aa3d31b0b7ac4ed038f92acbbd9a96fca02927640a104afdf96
MD5 9ef03024a88d664bd8ed933d972d749b
BLAKE2b-256 a55d05451a8efe6cd6f4940d2703af012ab44bc23189a07920ef8b8115f09322

See more details on using hashes here.

File details

Details for the file objectstore_client-0.0.15-py3-none-any.whl.

File metadata

File hashes

Hashes for objectstore_client-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 88c2247016ae947bcd83a93bd7788d5f9f8abb04980008f932b3f47da1ebce73
MD5 62ad4619ee89f9be639b2d1a6ffb036f
BLAKE2b-256 a5aa93f1ac84f0f021d3a89b9b2e50af8f8b38d699859cfd2d115a6a6369da9d

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