1
00:00:00,430 --> 00:00:02,188
- [Narrator] Hi and
welcome back to the course.

2
00:00:02,188 --> 00:00:05,853
In this video, we're getting
started with Sequel Alchemy

3
00:00:05,853 --> 00:00:09,104
which is a piece of software
that is going to allow us

4
00:00:09,104 --> 00:00:13,104
to very easily map our
objects to database rows.

5
00:00:14,755 --> 00:00:18,113
Now that may seem a bit
weird and a bit confusing,

6
00:00:18,113 --> 00:00:19,729
but don't worry because
throughout this section

7
00:00:19,729 --> 00:00:22,579
we're going to explore
exactly what that means,

8
00:00:22,579 --> 00:00:25,351
and what that means
particularly in regards to

9
00:00:25,351 --> 00:00:29,525
how easy it is to code and
to save things to a database

10
00:00:29,525 --> 00:00:32,594
as well as delete them and
update them and things like that.

11
00:00:32,594 --> 00:00:34,524
Essentially it's going to
make things really easy.

12
00:00:34,524 --> 00:00:36,276
So let's begin.

13
00:00:36,276 --> 00:00:39,222
I've created the new
folder here in my sort of

14
00:00:39,222 --> 00:00:42,754
course area and I'm
just going to once again

15
00:00:42,754 --> 00:00:45,872
walk you through the process
that I use for creating

16
00:00:45,872 --> 00:00:46,955
new projects.

17
00:00:49,136 --> 00:00:51,132
I've got the section
six folder, so the first

18
00:00:51,132 --> 00:00:53,748
thing I'm going to do
is create a code folder,

19
00:00:53,748 --> 00:00:56,726
and inside that folder all
my code is going to be,

20
00:00:56,726 --> 00:00:57,956
and then I'm also going to create

21
00:00:57,956 --> 00:01:01,096
a virtual environment for this project,

22
00:01:01,096 --> 00:01:04,263
so I'm going to do a virtualenv, venv,

23
00:01:04,263 --> 00:01:06,639
remember that's the name
of the virtual environment,

24
00:01:06,639 --> 00:01:09,544
dash, dash, python, equals python 3.5,

25
00:01:09,544 --> 00:01:11,706
and all that's gonna do is make
sure the virtual environment

26
00:01:11,706 --> 00:01:14,956
uses Python 3.5 as the base interpreter

27
00:01:16,159 --> 00:01:18,183
for the virtual environment.

28
00:01:18,183 --> 00:01:21,295
Remember if you don't do
that it will use the system

29
00:01:21,295 --> 00:01:24,128
Python which on Mac is Python 2.7.

30
00:01:24,998 --> 00:01:27,802
On Windows it will be the
Python version you've installed,

31
00:01:27,802 --> 00:01:31,218
and if you've got Python
2.7, as well as Python 3.5,

32
00:01:31,218 --> 00:01:33,930
it will be Python 2.7 by default.

33
00:01:33,930 --> 00:01:36,426
So just make sure to specify that.

34
00:01:36,426 --> 00:01:37,259
Okay?

35
00:01:37,259 --> 00:01:39,903
Now all that's done, and
the only thing we have to do

36
00:01:39,903 --> 00:01:42,530
is to activate the virtual environment

37
00:01:42,530 --> 00:01:45,758
so that we are using the
virtual environment's Python

38
00:01:45,758 --> 00:01:48,475
as opposed to the system's Python.

39
00:01:48,475 --> 00:01:52,642
So remember, on Mac, we'll do
source venv, bin, activate,

40
00:01:55,271 --> 00:01:59,438
and on Windows you would do
venv, scripts, activate.bat.

41
00:02:02,984 --> 00:02:03,817
Okay?

42
00:02:03,817 --> 00:02:05,987
So that's the command
you would run on Windows,

43
00:02:05,987 --> 00:02:07,374
on Mac that doesn't work,

44
00:02:07,374 --> 00:02:11,737
on Mac you have to do
source, venv, bin, activate.

45
00:02:15,963 --> 00:02:18,017
Now that we're here,
let's instal the things

46
00:02:18,017 --> 00:02:20,809
that we need for this project.

47
00:02:20,809 --> 00:02:21,642
The first thing that I'm gonna do

48
00:02:21,642 --> 00:02:23,652
is pip, instal, Flask.

49
00:02:23,652 --> 00:02:26,028
That's always gonna be necessary.

50
00:02:26,028 --> 00:02:27,529
I make it as very quick
because I've already

51
00:02:27,529 --> 00:02:29,589
got everything downloaded.

52
00:02:29,589 --> 00:02:32,973
Then we're gonna instal Flask, JWT,

53
00:02:32,973 --> 00:02:36,666
remember that's what's
necessary for authentication.

54
00:02:36,666 --> 00:02:40,249
Then we're going to instal Flask, Restful,

55
00:02:42,168 --> 00:02:45,918
that's what's necessary
for our API mappings.

56
00:02:47,164 --> 00:02:50,914
And now a new package,
Flask, sequel alchemy.

57
00:02:51,912 --> 00:02:54,798
And that essentially is Sequel Alchemy,

58
00:02:54,798 --> 00:02:57,115
which is a very large and popular library,

59
00:02:57,115 --> 00:03:00,204
but transposed into Flask to make things

60
00:03:00,204 --> 00:03:03,749
a bit easier to work with
from within our Flask app.

61
00:03:03,749 --> 00:03:07,290
Once we know about Flask's Sequel Alchemy,

62
00:03:07,290 --> 00:03:10,369
we'll be able to use
Sequel Alchemy very easily.

63
00:03:10,369 --> 00:03:12,969
There's very, very little
difference between the two,

64
00:03:12,969 --> 00:03:16,115
and Flask's Sequel Alchemy
depends on Sequel Alchemy,

65
00:03:16,115 --> 00:03:19,032
so basically all of the stuff
that is in Sequel Alchemy

66
00:03:19,032 --> 00:03:20,693
is also in Flask Sequel Alchemy.

67
00:03:20,693 --> 00:03:21,526
It doesn't really do much

68
00:03:21,526 --> 00:03:24,916
apart from make things a bit easier.

69
00:03:24,916 --> 00:03:27,909
Now that we've got
that, what we have to do

70
00:03:27,909 --> 00:03:32,076
is make sure that we copy that
code from the last section,

71
00:03:33,000 --> 00:03:34,833
into this code folder.

72
00:03:35,900 --> 00:03:38,423
Now, I'm gonna do that because
throughout these sections

73
00:03:38,423 --> 00:03:42,569
we're building up the same
API to make things easier

74
00:03:42,569 --> 00:03:45,298
for you, and to make sure
that the concepts stick

75
00:03:45,298 --> 00:03:46,904
from one section to another.

76
00:03:46,904 --> 00:03:49,434
And then at the end we're
gonna work on a larger project,

77
00:03:49,434 --> 00:03:51,191
but for this section, let's copy the code

78
00:03:51,191 --> 00:03:54,426
from the previous section
into the code folder.

79
00:03:54,426 --> 00:03:58,021
So you can do that using
Windows Explorer or the finder

80
00:03:58,021 --> 00:04:00,082
or even Atom if you prefer.

81
00:04:00,082 --> 00:04:01,672
I'm going to do it with
a terminal because it's

82
00:04:01,672 --> 00:04:03,266
a bit simpler for me, but again,

83
00:04:03,266 --> 00:04:04,832
all we're doing is copying the code

84
00:04:04,832 --> 00:04:07,923
from section five into the code folder

85
00:04:07,923 --> 00:04:09,124
that we've created.

86
00:04:09,124 --> 00:04:13,291
So what I'm going to do is
CP, section five, code star,

87
00:04:16,893 --> 00:04:17,726
into code.

88
00:04:19,737 --> 00:04:21,679
And that's fine.

89
00:04:21,679 --> 00:04:25,066
I get a wee error there
saying that the pycache

90
00:04:25,066 --> 00:04:28,341
item was not copied because it's a folder

91
00:04:28,341 --> 00:04:29,706
as opposed to a file,

92
00:04:29,706 --> 00:04:30,953
and that's fine.

93
00:04:30,953 --> 00:04:32,124
I don't really care about that folder.

94
00:04:32,124 --> 00:04:36,291
That folder is just keeping
things that Python uses

95
00:04:37,828 --> 00:04:40,461
so that it can reuse
them quickly essentially.

96
00:04:40,461 --> 00:04:42,800
Okay, now we're going to
look into the code folder

97
00:04:42,800 --> 00:04:45,600
and as you can see we've
copied a bunch of things.

98
00:04:45,600 --> 00:04:49,517
We've copied app.py,
create tables.py, data.db,

99
00:04:50,426 --> 00:04:53,259
item.py, security.py, and user.py.

100
00:04:54,991 --> 00:04:58,018
I'm going to remove data.db,

101
00:04:58,018 --> 00:04:59,920
and once again you can do
this through the terminal

102
00:04:59,920 --> 00:05:02,855
if you want, or through Atom or through

103
00:05:02,855 --> 00:05:04,338
Windows Explorer or finder.

104
00:05:04,338 --> 00:05:05,639
It doesn't matter how you do it

105
00:05:05,639 --> 00:05:09,266
but I'm just gonna remove data.db so that

106
00:05:09,266 --> 00:05:13,935
we make sure that when we
create the file data.db again,

107
00:05:13,935 --> 00:05:15,738
it works, and it's not using

108
00:05:15,738 --> 00:05:18,633
the data.db from the last section.

109
00:05:18,633 --> 00:05:21,367
Okay, now that all of this is done,

110
00:05:21,367 --> 00:05:23,561
which was this sort of set up,

111
00:05:23,561 --> 00:05:27,144
we're going to run Atom
in the code folder.

112
00:05:28,172 --> 00:05:30,991
So again, you just run Atom and open

113
00:05:30,991 --> 00:05:33,643
the code folder, I'm gonna
do it through the terminal

114
00:05:33,643 --> 00:05:35,160
because it's easier,

115
00:05:35,160 --> 00:05:37,927
but if that doesn't work for you,

116
00:05:37,927 --> 00:05:41,177
you can always just open Atom as normal

117
00:05:42,849 --> 00:05:46,128
and open the code folder
by going to file, open.

118
00:05:46,128 --> 00:05:49,045
Okay, so no magic going on in here.

119
00:05:50,208 --> 00:05:52,293
So now what we've got
is what no one loves,

120
00:05:52,293 --> 00:05:53,895
which is the code folder,

121
00:05:53,895 --> 00:05:56,312
and in it, we've got our app,

122
00:05:57,384 --> 00:06:01,166
create tables, item.py,
security.py, and user.py.

123
00:06:01,166 --> 00:06:03,511
Okay, so we're now ready
to continue in the next

124
00:06:03,511 --> 00:06:07,496
video where we're gonna get
started coding this new project.

125
00:06:07,496 --> 00:06:08,823
I'll see you there.

