Skip to main content

datasource-python

Python SDK for all DataSource iterations

Installation

Install this package via pip:

pip install bocks_ds

Usage

The Client

Import this package and instantiate a client object.

import bocks_ds

ds_client = bocks_ds.Client("starfinder") # provide the name of the datasource to access

Error Example:

try:
    bad_client = Client("bad_client")
except DSTargetError as e:
    print(e) # The target 'bad_client' provided in Client initialization is not in available target names:\n['starfinder', 'pathfinder']

Fetching Data

There are currently only two options to consider when fetching data: the type and the parameters.

The "type" can be thought of as a data table, though we will discuss some complexities later on.

response = ds_client.armor.get(['name', 'price']) # 'armor' here is the query type
if response.status_code == 200: # optional status check
    data = response.json() # '.json()' gives the API data output we came for

Note that the ds_client will accept any value as an attribute, which it will then use to craft an API request.

Error Example:

try:
    client.bad_name.get(['name']).json()
except DSQueryError as e:
    print(e) # <Response 400> DataSource did not find table/field 'bad_name'.

Refining Your Request

The API allows for active filtering of strings and integers within your request. To do this, you'll need to set arguments immediately prior to making the request.

For data values that return strings, you may refine with the terms <value_name>_like and <value_name>_is. For "like" queries, sequencing is not considered and the search is not case sensitive. For "is" queries, only exact, case-sensitive matches will be returned.

For data values that return integers, you may refine with the terms <value_name>_min, <value_name>_max and <value_name>_equals. These equate to "greater than or eqal to", "less than or equal to", and "equal to", respectively.

Finally, it is often valuable to select an item specifically by its ID, which functions in a more direct manner than the queries for integers (see example below).

All arguments must be presented as a single dictionary, as seen in the examples below.

client.armor.set_arguments({"name_like":"basic"})
response = ds_client.armor.get(['name', 'price'])
client.armor.set_arguments({"price_min":200, "price_max":2000})
response = ds_client.armor.get(['name', 'price'])
client.armor.set_arguments({"id":1})
response = ds_client.armor.get(['name', 'price'])

Note that these requests do not stack, but you can place all terms into a single dictionary to futher refine results. If set_arguments is called multiple times, the final call will overwrite previous calls.

query = {"name_like":"basic", "price_min":200, "price_max":2000}
client.armor.set_arguments(query)
response = ds_client.armor.get(['name', 'price'])

As a final note: all arguments are cleared when get is called.

Error Example

try:
    client.armor.set_arguments({"name_min":200})
    erroneous_armor = client.armor.get(['name', 'price']) # Throws exception due to errors in response.json()
except DSQueryError as e:
    print(e) # <Response 400> ['Unknown argument "name_min" on field "Query.armor". Did you mean "name_is", "name_like", "type_min", "bulk_min", or "level_min"?']

Fetching Nested Data

As mentioned previously, not all types match their data tables precisely. Some types include additional data from relationships with other tables. Documentation for these relationships is automatically generated in the API Documentation (such as at docs.sfdatasource.com).

In order to access nested data, it is required that you present a dictionary describing the data to fetch.

Where we previously provided a list of string field-names to query, we will now include a dictionary in that list, as seen in the examples below.

query = [
    "name",
    {
        "effect_ranges": ["name", "description"],
    }
]
all_spells = ds_client.spells.get(query)

This logic is recursive, so in the event that a relationship target has it's own relationships you may do the following:

query = [
    "name",
    {
        "class_proficiencies": ['name'],
        "class_features": ["name", {
            "class_special_skills": ['name']
        }],
    }
]
spells = client.classes.get(query)

Metadata

Release files for bocks-ds 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bocks-ds 0.2.1
File Size Uploaded Provenance Actions
bocks_ds-0.2.1.tar.gz 5.7 kB Without provenance Details for bocks_ds-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bocks-ds 0.2.1
File Interpreter ABI Platform Actions
bocks_ds-0.2.1-py3-none-any.whl Python 3 none any Details for bocks_ds-0.2.1-py3-none-any.whl

Total release size: 25.1 kB

Release files / bocks_ds-0.2.1.tar.gz

Download URL bocks_ds-0.2.1.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f0be2ede121ec1eddbae1d7348786d4ec663384145d08691bd4da31940f532bd
BLAKE2b-256 checksum
How to use checksums
448b051bf52b3e9d629e5cc36be980309d915cad7e92398111ad7640ae56a1b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

Release files / bocks_ds-0.2.1-py3-none-any.whl

Download URL bocks_ds-0.2.1-py3-none-any.whl
Size 19.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfdb371539de1ec3580499ca4902ef405cd739c60d871bf696f9e3574b3c44af
BLAKE2b-256 checksum
How to use checksums
a95e056ebb7e9022337a7010819a5e0652325f5d01178aa3e0007f2a346b45f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

Security for bocks-ds 0.2.1

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.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files No provenance

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