Skip to main content

The Official Python Client of the Array of Things API

Project description

# Plenario Client

This library serves as the official Python client to the
[Plenario API](https://plenario.docs.apiary.io/#).

## Requirements

This will run on Python 3.6 or better. Older versions of Python are not
supported. This library requires the installation of the
[requests library](http://docs.python-requests.org/en/master/).

## Usage

There are 2 API endpoints to Plenario:

- The list endpoint that gets metadata about the data sets
- The detail endpoint that gets records from the data sets

### Accessing Data Set Records

Plenario API responses are paginated, so naturally we need to provide users
with the ability to page through data as easily as possible. To do this, we
provide a simple iterator baked into the data sets:

```python
from plenario_client import PlenarioClient

client = PlenarioClient()
data_set = client.get_data_set('chicago-stuff')
for page in data_set:
do_something_with_the(page)
```

The _page_ here is the response object: it has a `meta` attribute that includes
the response metadata and a `records` attribute that includes the response
body -- a list of dictionaries.

### Filtering with Query Parameters

Filtering can be a little complicated depending on your needs. To handle that,
we've come up with a pretty simple solution. Somewhat similar to Django and
Elasticsearch-DSL we have an `F` class with which you construct and compose
query parameters to filter the results.

There are three operations:

- Basic init with `F('field name', 'query operator', 'query value')`
- Appending filters with `F() &= F()`
- Overriding filters with `F() |= F()`

Here's an example:

```python
from plenario_client import PlenarioClient, F

# let's build a filter where we want items whose name is 'vince'
# and their age is greater than or equal to 21:
params = F('name', 'eq', 'vince')
params &= ('age', 'ge', 21) # appending works with either an F or a tuple

# let's now say we want to add 'bob' to the filter as well:
params &= ('name', 'eq', 'bob')

# at this point if we inspect the filter we would get something like
{
'name': [
('eq', 'vince'),
('eq', 'bob')
],
'age': ('ge', 21)
}

# now let's say that due to some logic happening in our script,
# we've determined that neither 'vince' nor 'bob' are desireable
# values -- we need 'alice':
params |= ('name', 'eq', 'alice')

# now under the hood, our filter looks like
{
'name': ('eq', 'alice'),
'age': ('ge', 21)
}

# now we're ready to fire off the request:
client = PlenarioClient()
client.describe_data_sets(params=params)
```

## Developing and Contributing

To run the tests locally:

```bash
$ pipenv install --dev
$ pipenv run python -m pytest
```

To push a relase to PyPI:

```bash
$ pipenv run python setup.py sdist bdist_wheel
$ pipenv run twine upload dist/*
```

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

plenario-client-0.9.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

plenario_client-0.9.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file plenario-client-0.9.0.tar.gz.

File metadata

  • Download URL: plenario-client-0.9.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for plenario-client-0.9.0.tar.gz
Algorithm Hash digest
SHA256 2825e93c76c68136b3c7889199f7fb1fbd364f857050dc136596e130d9244006
MD5 b48bd9741ec4f7387c0943d3f71167bf
BLAKE2b-256 856b7353b3a05bcb2b213f786365a50f46ac932f935bf5ef67dd4b97bf532960

See more details on using hashes here.

File details

Details for the file plenario_client-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: plenario_client-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for plenario_client-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8badb231912a5dd7385536aa3ce3da1f6da54b72981ebd429f27e066c1bf404b
MD5 8b11e5262fb1f7cc674a4a645650d6dc
BLAKE2b-256 c309f9fb543bc9bf307777e4c37ef913635a2c1608ed6d45252f08bff3f31ff2

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