Module leapyear

The LeapYear Client connects the python API to the LeapYear server.

While connected to the server, the connection information is stored in a resource manager, so direct access to the client is not necessary for all operations.

The main objects that can be directly accessed by the Client object are databases, users and permissions resources. Many resources are cached to reduce network latency, however the load() methods for resource objects will force refreshing of the metadata.

>>> from leapyear import Client
>>> from leapyear.admin import Database, Table, Column, Type

Connecting to the server

  • Method 1 - manually open and close the connection.

>>> SERVER_URL = 'https://ly-server:4408'
>>> client = Client(url=SERVER_URL)
>>> print(client.databases)
{}
>>> client.close()
  • Method 2 - Use a context to automatically close the connection.

>>> with Client(url=SERVER_URL) as client:
...     print(client.databases)
{}

Create a User

There are two ways to create an object on the LeapYear server. The first is to invoke the Client.create() method.

>>> with Client(url=SERVER_URL) as client:
...     client.create(User('new_user', 'password'))

The second is to call the create() method on the object.

>>> with Client(url=SERVER_URL) as client:
...     User('new_user', 'password').create()

Create a Database

>>> with Client(url=SERVER_URL) as client:
...     db = Database('db_name')
...     client.create(db)
...     print(db.tables)
{}

Create a Table

>>> TABLE_CREDENTIALS = 'hdfs://path/to/data.parq'
>>> columns = [
>>>    Column('x', Type.REAL(-3.0,3.0)),
>>>    Column('y', Type.BOOL()),
>>> ]
>>> with Client(url=SERVER_URL) as client:
...     tbl = Table(
...         'tbl_name',
...         columns,
...         credentials=TABLE_CREDENTIALS,
...         database=db,
...     )
...     tbl.create()  # doctest: +SKIP

The Client class

class leapyear.client.Client(url='http://localhost:4408', username=None, password=None, *, token=None, default_analysis_caching=True, default_allow_max_budget_allocation=True)

A class that wraps a connection to a LeapYear system.

close()

Close the LeapYear connection.

Return type

None

clear_analysis_cache()

Clear all analyses from the cache.

Return type

None

clear_all_caches()

Clear all of the caches.

Return type

None

count_analysis_cache()

Return the number of analyses in the analysis cache.

Return type

int

unpersist_all_relations()

Clear all cached datasets.

Return type

None

property logger

Get the Logger object for the client.

Return type

Logger

property url

Get the URL of the connection.

Return type

str

property username

Get the user currently logged in the server.

Return type

str

property connected

Check if the client is connected.

Return type

bool

create(obj, drop_if_exists=False)

Create an object on the LeapYear server.

Return type

None

create_async(obj)

Create an object on the LeapYear server asynchronously.

Return type

NewType()(AsyncJobId, str)

update(obj, **kwargs)

Update an object on the LeapYear server.

Return type

None

drop(obj, ignore_missing=False)

Drop an object on the LeapYear server.

Return type

None

property databases

Get all databases available on the server.

Return type

Mapping[str, Database]

property current_user

Get the currently logged in user.

Return type

User

property users

Get users available on the server.

Return type

Mapping[str, User]

property groups

Get groups available on the server.

Return type

Mapping[str, Group]

property jobs

Get running jobs on the server.

Return type

List[AsyncJobInformation]

property finished_jobs

Get running jobs on the server.

Return type

List[AsyncJobInformation]