diff --git a/pyproject.toml b/pyproject.toml index 96cecc1..a1e9e6c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,10 +4,10 @@ build-backend = "setuptools.build_meta" [project] name = "pyflapjack" -version = "1.0.6" +version = "1.0.14" description = "Python package that interfaces the Flapjack API" readme = "README.md" -requires-python = ">=3.7" +requires-python = ">=3.7,<3.11" license = {file = "LICENSE"} keywords = ["flapjack", "data", "experimental", "analysis", "synthetic biology"] authors = [ @@ -24,18 +24,18 @@ classifiers = [ ] dependencies = [ - 'numpy==1.21.2', - 'scipy==1.8.0', - 'pandas==1.3.3', - 'requests==2.26.0', + 'numpy== 1.26.2', + 'scipy==1.11.0', + 'pandas==1.5.3', + 'requests>=2.25.1', 'tqdm==4.62.3', 'plotly==5.3.1', 'asyncio==3.4.3', 'nest_asyncio==1.5.1', 'requests_jwt==0.5.3', 'websockets==10.0', - 'matplotlib==3.4.3', - 'kaleido' + 'matplotlib>=3.10', + 'kaleido==0.2.1' ] [project.optional-dependencies] diff --git a/src/flapjack/flapjack.py b/src/flapjack/flapjack.py index 1aaf5d0..b220e86 100644 --- a/src/flapjack/flapjack.py +++ b/src/flapjack/flapjack.py @@ -57,6 +57,25 @@ def __del__(self): def handle_response(self, s): return True + + # Sign in to the server + + def sign_up(self, username, password, email): + try: + s = requests.post( + self.http_url_base+'/api/auth/sign_up/', + data={ + 'username':username, + 'password':password, + 'email':email + } + ) + except: + print(f'Sign up failed.') + else: + if self.handle_response(s): + print(f'Successfully signed up as {username}.') + self.log_in(username, password) def register(self, username, password, password2, email): try: @@ -77,7 +96,17 @@ def register(self, username, password, password2, email): data = s.json() self.access_token = data['access'] self.refresh_token = data['refresh'] - + + def log_in_token(self, username, access_token, refresh_token): + try: + self.username = username + self.access_token = access_token + self.refresh_token = refresh_token + except: + print(f'Invalid token') + + + def log_in(self, username, password): try: s = requests.post( @@ -95,7 +124,6 @@ def log_in(self, username, password): data = s.json() self.access_token = data['access'] self.refresh_token = data['refresh'] - self.username = username def log_out(self): if self.username: @@ -103,7 +131,7 @@ def log_out(self): s = requests.post( self.http_url_base+'/api/auth/log_out/', data={ - 'username':username + 'username':self.username } ) except: @@ -165,7 +193,7 @@ def create(self, model, confirm=True, overwrite=False, **kwargs): headers={'Authorization': 'Bearer ' + self.access_token}, data=kwargs ) - elif len(existing) and overwrite == False: + elif len(existing) and not overwrite: print(f'Returning exististing model, {model}') return existing @@ -217,7 +245,7 @@ def get(self, model, **kwargs): url = data['next'] df = pd.DataFrame(results) # Convert ids from np.int64 to int - df.index = df.index.astype(np.int) + df.index = df.index.astype(int) return df def parse_params(self, **kwargs):